How to convert PNG and JPG to WebP (and when you shouldn't)

PageSpeed keeps telling you to serve WebP? How to convert PNG and JPG to WebP online or from the command line, which settings to use, and when to keep JPG.

By Devdeep 5 min read
A PNG chart and a JPG photo converted to WebP, each ending up smaller

If you've ever run your site through PageSpeed Insights, you've probably seen it: a warning about image delivery that tells you to "serve images in next-gen formats". It usually comes with a long list of your PNGs and JPGs and a number showing how many kilobytes you'd save.

The fix in most cases is converting them to WebP. It's supported by every modern browser, it's usually a quarter to a third smaller than JPEG at the same quality, and the conversion itself takes seconds.

But there are a couple of decisions to make along the way, and getting them wrong either wastes the savings or makes your images look worse. So let's go through them.


PNG to WebP: lossless or lossy?

This is the decision that matters most, and it depends on what's actually in the PNG.

If the PNG is a screenshot, logo, chart or UI graphic, use lossless WebP. It keeps every pixel exactly the same, keeps transparency, and is typically around a quarter smaller than the PNG. There's no quality trade-off at all, so there's no reason not to.

If the PNG is a photo, use lossy WebP. This is a really common mistake on websites: someone exports a photo as PNG because "PNG is higher quality", and you end up with a 5 MB file for a picture that would be 300 KB as a WebP with no visible difference. PNG is designed for flat graphics. It's terrible at photos.

Not sure which you have? Look at it. Big areas of flat colour and sharp edges mean graphic. Gradients, texture and noise mean photo.

Both lossless and lossy WebP keep transparency, so a product shot on a transparent background stays transparent either way.


JPG to WebP: set your expectations

Converting a JPG to WebP works well, with one caveat. A JPG has already been through lossy compression once. Converting it means compressing it again, and each round throws away a little more detail.

In practice, at WebP quality 75–82 the result looks the same and is still noticeably smaller. But two tips:

  • Start from the original if you have it. If the JPG came out of Lightroom or a camera, go back to the high-quality export rather than converting the copy that's already on your site.
  • Don't expect big savings from already-crushed JPGs. If the JPG was saved at quality 60, there isn't much fat left to trim. You might get 10–15%, not 30%.

Converting online with TinyRes

The fastest way to convert a batch:

  1. Open TinyRes and drop your PNG or JPG files in.
  2. Pick a preset:
    • Web optimised for photos: WebP at quality 80, EXIF data stripped.
    • Lossless for screenshots, logos and graphics: pixel-exact WebP.
  3. Apply, check the preview, and download them individually or as a ZIP.

While you're at it, check the dimensions. If your blog column is 800 pixels wide, a 3000-pixel image is mostly wasted bytes no matter which format it's in. Setting the width in the Resize tab often saves more than the format change does. We've written a whole post on what size images should be for a website.

TinyRes is free for 20 images a day, each up to 20 MB, with no account. Files are converted in memory and nothing is stored.


Converting from the command line

If you're a developer with a folder full of images, Google's own cwebp tool is the classic way. On a Mac with Homebrew it's brew install webp, and most Linux distributions have a webp package.

Lossy, for photos:

cwebp -q 80 photo.jpg -o photo.webp

Lossless, for graphics:

cwebp -lossless screenshot.png -o screenshot.webp

And a whole folder of JPGs at once:

for f in *.jpg; do cwebp -q 80 "$f" -o "${f%.jpg}.webp"; done

When you shouldn't convert to WebP

WebP is a web format. It's great inside a browser. Outside one, it can still cause headaches:

  • Email newsletters. Email clients are years behind browsers. Some desktop versions of Outlook still won't show WebP. Use JPG and PNG in emails.
  • Upload forms. Government sites, job portals and exam forms usually want JPG or PNG only.
  • Sending photos to people. Someone opening an attachment on an old laptop or a smart TV may not be able to view it.
  • Printing. Print shops expect JPG, TIFF or PDF.
  • Your master copies. Keep the originals. Convert copies for the web, so you can re-export later at a different size or in a better format without losing quality twice.

Should you skip WebP and go straight to AVIF?

For photos on a website, AVIF is usually even smaller. The catch is that it's slower to encode and has a few quirks. Many sites serve AVIF with WebP as a fallback using the <picture> element. I've covered the trade-offs in AVIF vs WebP vs JPEG.

But if you want one simple, safe change you can make today, converting your PNGs and JPGs to WebP is it. It's one of the few performance fixes that's basically all upside.

zero bytes stored

Shrink your images right now

Convert to AVIF, WebP or MozJPEG, crop around faces, strip EXIF and hit exact KB targets in your browser.