Prompt
How do I convert JPEG and PNG files to WebP for a website?
Latest observation
Nov 3, 2026
OpenAI APIWeb search: off
You can convert JPEG and PNG images to WebP using a few common methods, depending on your workflow.
1) Using command line tools
With cwebp (Google’s WebP tool)
Install it first, then convert:
cwebp input.jpg -o output.webp
cwebp input.png -o output.webp
Useful options:
cwebp -q 80 input.jpg -o output.webp
-q 80sets quality (0–100).- Lower = smaller file, but lower quality.
Batch convert with a shell loop
for file in *.jpg *.png; do
cwebp "$file" -o "${file%.*}.webp"
done
2) Using ImageMagick
If you already use ImageMagick:
magick input.jpg output.webp
magick input.png output.webp
You can control quality too:
magick input.jpg -quality 80 output.webp
3) Using online converters
If you only have a few images, you can use online WebP converters.
Good for quick jobs, but not ideal for sensitive images or large batches.
4) In a build pipeline
For websites, it’s often best to automate conversion during your build/deploy process:
- Node.js: use packages like
sharp - Python: use Pillow with WebP support
- CI/CD: convert assets before deployment
Example with sharp in Node.js:
import sharp from "sharp";
sharp("input.jpg").webp({ quality: 80 }).toFile("output.webp");
5) Serving WebP on your website
Once converted, you can serve WebP with a fallback for browsers that don’t support it:
<picture>
<source srcset="image.webp" type="image/webp">
<img src="image.jpg" alt="Description">
</picture>
This way:
- WebP is used when supported
- JPEG/PNG is used as fallback
Recommended approach
For most websites:
- Convert images to WebP during your build process
- Keep original JPEG/PNG as fallback
- Use
<picture>or server-side content negotiation
If you want, I can also show you:
- how to do this on Windows
- how to batch convert an entire folder
- or how to set it up in Node.js / Python