Prompt
How do I generate AVIF and WebP versions of images?
Latest observation
Nov 2, 2026
OpenAI APIWeb search: off
You can generate AVIF and WebP versions of images using either command-line tools or libraries in your app/build pipeline.
1) Using ImageMagick + compatible encoders
If your ImageMagick build supports them:
magick input.jpg output.webp
magick input.jpg output.avif
If AVIF/WebP support isn’t available, you may need extra libraries installed (libwebp, libavif, etc.).
2) Using ffmpeg for single images
For still images, ffmpeg can convert formats:
ffmpeg -i input.jpg output.webp
ffmpeg -i input.jpg output.avif
3) Using cwebp and avifenc directly
These are usually the best options.
WebP
Install cwebp (from the WebP tools package), then:
cwebp input.jpg -q 80 -o output.webp
AVIF
Install avifenc (from libavif tools), then:
avifenc --min 20 --max 50 input.jpg output.avif
You can also tune quality:
- lower values = smaller files, lower quality
- higher values = larger files, better quality
4) Batch convert with a shell loop
WebP
for f in *.jpg; do
cwebp "$f" -q 80 -o "${f%.jpg}.webp"
done
AVIF
for f in *.jpg; do
avifenc "$f" "${f%.jpg}.avif"
done
5) In JavaScript / Node.js
You can use libraries like:
- sharp (popular, fast)
- imagemin-webp
- @squoosh/lib
Example with sharp:
import sharp from "sharp";
await sharp("input.jpg").webp({ quality: 80 }).toFile("output.webp");
await sharp("input.jpg").avif({ quality: 50 }).toFile("output.avif");
6) In a build pipeline
If you’re generating assets for a website, you can automate conversion in:
- Webpack
- Vite
- Gulp
- npm scripts
- CI/CD
Example npm script:
{
"scripts": {
"convert": "node convert-images.js"
}
}
7) Serving both formats on the web
Use <picture> so browsers pick the best supported format:
<picture>
<source srcset="image.avif" type="image/avif">
<source srcset="image.webp" type="image/webp">
<img src="image.jpg" alt="Example">
</picture>
If you want, I can also show you:
- the best quality/compression settings
- how to do this on Windows/macOS/Linux
- a Node.js batch converter script
- how to generate responsive sizes too