Batch Image Conversion: Save Time with Bulk Processing
Convert folders of images to WebP in one pass — browser tools, cwebp, ImageMagick, FFmpeg and Sharp scripts — plus how to verify the savings and avoid the common batch-conversion traps.
A single image is easy to convert by hand. A product catalogue, a documentation site or a photography portfolio is not. Batch processing turns a tedious chore into a step you stop thinking about.
Why batch instead of one at a time
- Consistency. Every image goes through the same quality setting, so your page weight is predictable.
- Time. Converting on the web in batches takes seconds per round; a command line tool handles thousands in one pass.
- Traceability. When you process a folder at once you can compare the before and after sizes and see immediately whether the settings worked.
Converting a small batch in the browser
The IMG2WEBP converter accepts up to five images per batch, each up to 5MB:
- Drag your images onto the upload area, or pick them with the file browser.
- Set the quality slider. 80 is a good default for photographs; go higher for screenshots and text.
- Convert, then download the results individually or as a single ZIP archive.
For a checkout page, a blog post or a landing page’s hero group, that is usually all you need. If you are converting a specific source format, the dedicated pages for JPG, PNG and GIF explain the settings that matter for each.
Converting a large library from the command line
Once you are dealing with hundreds of files, script it.
cwebp (official WebP encoder)
cwebp comes from Google’s libwebp and is the fastest option for WebP specifically:
# Install: brew install webp (macOS) / sudo apt install webp (Debian)
mkdir -p webp
for file in ./images/*.{jpg,png}; do
cwebp -q 80 "$file" -o "./webp/$(basename "${file%.*}").webp"
done
On a multi-core machine, run it in parallel with GNU parallel:
ls ./images/*.jpg | parallel cwebp -q 82 {} -o ./webp/{/.}.webp
ImageMagick
ImageMagick handles 200+ formats and can resize while it converts. mogrify writes in place, so always target a separate output directory:
# ImageMagick 7
magick mogrify -path ./webp -format webp -quality 82 -resize 1600x ./*.jpg
# ImageMagick 6
mogrify -path ./webp -format webp -quality 82 -resize 1600x ./*.jpg
FFmpeg
Useful when your pipeline already depends on FFmpeg, or when you need AVIF output as well:
for f in ./images/*.png; do
ffmpeg -i "$f" -c:v libwebp -quality 82 "./webp/$(basename "${f%.png}").webp"
done
Sharp (Node) or Pillow (Python)
For anything more complex than a one-liner — renaming, filtering, extracting dominant colours — a small script is easier to maintain. A Sharp version that emits both WebP and AVIF:
import sharp from 'sharp';
import { readdir } from 'node:fs/promises';
const files = (await readdir('./images')).filter((f) => /\.(jpe?g|png)$/i.test(f));
for (const file of files) {
const base = file.replace(/\.\w+$/, '');
const img = sharp(`./images/${file}`).resize({ width: 1600, withoutEnlargement: true });
await img.clone().webp({ quality: 82 }).toFile(`./out/${base}.webp`);
await img.clone().avif({ quality: 50 }).toFile(`./out/${base}.avif`);
}
Which tool should you use?
| Tool | Best for | Speed | Setup |
|---|---|---|---|
| Online converter | Up to a few dozen files, no install | Fast | None |
| cwebp | WebP only, large folders | Very fast | Low |
| ImageMagick | Mixed formats, resize + convert | Medium | Low |
| FFmpeg | WebP and AVIF, pipelines | Fast | Medium |
| Sharp / Pillow | Custom logic, build integration | Medium | Medium |
Checking the result
Whatever route you take, verify two things:
- Visual quality. Open a few converted files at full size, not thumbnails. Artefacts hide until you look closely.
- Correct markup. Serving WebP only helps if the page actually requests it, so check that your
srcsetor format negotiation is picking the new files.
Then compare the totals:
du -sh ./images ./webp
Common batch-conversion traps
- Output larger than the input. If a source JPEG was already heavily compressed, the WebP can come out slightly bigger. Sort your results by size and keep whichever file is smaller.
- Blanket lossy settings. Screenshots, logos and text need lossless mode or a high quality value; applying a photo preset to everything produces visible artefacts.
- GIF transparency. GIF only has 1-bit transparency, so converting it with a lossy preset can increase the file size. Use an animated-WebP tool such as
gif2webpfor animations instead. - Overwriting originals. Never convert in place without a backup. Lossy conversion is irreversible.
These mirror the deeper trade-offs we cover in The Complete Guide to WebP.
Keeping it repeatable
Automate the conversion in your build or asset pipeline rather than doing it once by hand. Future image additions then get the same treatment automatically, and the “do we compress before or after export?” question stops coming up in code review.
A lightweight pattern is to run the conversion script on a pre-commit hook or as a CI step, commit the optimised output, and let the pipeline fail if a new image sneaks in unoptimised.
Frequently asked questions
How many images can I batch convert at once?
Browser tools cap out for safety and speed — IMG2WEBP takes five files per batch. Command line tools have no practical limit; the constraint is your disk and CPU, so a typical machine handles thousands of medium JPEGs per run.
Will batch conversion lose quality?
A lossy conversion discards data, but at quality 80-85 the change is invisible on photographs at normal viewing sizes. For screenshots, logos and text, use a higher quality value or lossless mode instead.
Can I convert a whole folder to WebP without installing anything?
Yes, in batches through the browser converter. For hundreds of files, a local tool is faster because nothing has to be uploaded and downloaded — see our tips for faster image pipelines.
Why is my converted WebP larger than the original JPEG?
Usually because the JPEG was already aggressively compressed, or because the image has fine detail that lossy WebP does not compress as well. Lower the quality value, or keep the smaller of the two files.
Summary
Use the browser converter for small batches and a script for large ones, always keep the originals, and measure the size difference so you know the settings are doing what you expect. Then wire the script into your build so it keeps happening without you.