AVIF is usually the smallest of the modern web image formats — often 20–30% below WebP at comparable quality — and it keeps an alpha channel, so it’s a strong choice for transparent PNGs like logos and icons. The trade-off is encode time: AVIF is slower to produce than WebP. This guide converts a whole folder to .avif in one command, locally, with no upload.
Everything runs against @assetopt/cli (open source, MIT). The number at the end comes from the downloadable sample pack — a real file, not a cherry-picked benchmark. If you only care about WebP, see the companion guide, Convert JPG & PNG to WebP in bulk.
Install
npm install -g @assetopt/cli
Or run it without installing:
npx @assetopt/cli --help
Convert a folder to AVIF
By default the CLI recompresses images in their original format. To target AVIF, add a .assetoptrc that routes your source formats to avif:
{
"images": {
"formatMatrix": { "jpeg": "avif", "png": "avif" },
"quality": { "avif": 55 }
},
"output": { "dir": "./optimized" }
}
Then run:
assetopt optimize ./images
Every .jpg and .png under ./images is written as .avif into ./optimized. Originals are left untouched.
To push every image (including existing WebP) to AVIF, use
{ "images": { "outputFormat": "avif" } }instead of a per-format matrix. See the config reference for the difference.
Preview the savings first
Run a dry run before writing anything — analyze reports exact before/after sizes without touching disk:
assetopt analyze ./images
Swap analyze for optimize once the numbers look right.
Pick a quality that fits
AVIF quality is a 1–100 dial (default 75). AVIF holds up well at lower numbers than JPEG, so 50–60 is often a good starting point for photos:
{ "images": { "formatMatrix": { "jpeg": "avif", "png": "avif" }, "quality": { "avif": 50 } } }
Because AVIF encoding is CPU-heavy, the incremental cache matters here: after the first run, only changed files are re-encoded, so re-running is fast.
The max-compression preset
If your goal is simply the smallest possible payload, the built-in max-compression preset converges every format to AVIF at quality.avif: 50, strips metadata, and fully optimizes SVG:
{ "preset": "max-compression" }
See the preset reference for exactly what each one does.
Real number
On the sample pack, a transparent logo PNG smart-routed to AVIF:
| Source | Before | After (AVIF) | Saved |
|---|---|---|---|
| Transparent logo PNG | 57 KB | 9.5 KB | −83.3% |
AVIF kept the alpha channel while cutting the file to a sixth of its size — the case where AVIF clearly beats WebP. You can reproduce this with the downloadable pack.
WebP or AVIF?
- AVIF: smallest files, keeps transparency, slower to encode. Best for logos/icons with alpha and for photos where build time isn’t critical.
- WebP: still much smaller than JPEG/PNG, far faster to encode, universally supported. A safe default for large photo batches.
You don’t have to choose globally. assetopt can route by content — transparent → AVIF, opaque → WebP — automatically. That’s what the web-perf preset does; see Smart format conversion.
Next steps
- Convert JPG & PNG to WebP in bulk — the faster-encoding sibling
- CLI reference — every command, flag, and exit code
- Configuration reference — all
.assetoptrcfields