How to Compress WebP Images While Preserving Visual Quality
Compress WebP images without visible quality loss: choose lossless or high-quality lossy encoding, keep transparency and dimensions, and check the result before replacing originals.
WebP supports both lossless and lossy compression, so a smaller file does not have to look worse. The result depends on which mode you choose, what you start from, and how you check the output. This guide covers one task: reducing WebP file size while keeping the image visually unchanged.
Before you start
Find the best source you have. If a PNG, TIFF or camera original exists, compress from it rather than from an existing lossy WebP. Each lossy re-encode discards more detail, and no tool can restore what an earlier encode removed.
Decide where the processing happens. A command-line encoder such as cwebp from the libwebp package, or a desktop image editor with WebP export, works on your own computer. A web-based compressor may upload your files to a server. For private photos, screenshots with personal data or client work, read the service's own description of how uploads are stored and deleted, and do not assume processing is local just because it runs in a browser.
- Keep an untouched copy of every original before you start.
- Note the original pixel dimensions and aspect ratio so you can confirm they did not change.
- Check whether the image uses transparency; logos, icons and cut-out product shots often do.
- Know whether you need the embedded metadata (camera data, color profile, copyright) or would rather strip it.
Step-by-step instructions
The steps below use cwebp because its options are documented and behave the same on Windows, macOS and Linux. Graphical tools usually expose the same ideas as a quality slider and a lossless checkbox, but their labels differ between apps and versions, so match the concept rather than a specific menu name.
- 1. Choose the compression mode. Use lossless for graphics, text, screenshots, line art and anything with sharp edges or flat color. Use high-quality lossy for photographs, where lossless files are often much larger.
- 2. For lossless output, run cwebp with the -lossless option and an output file name that differs from the original. Add -z followed by a number from 0 to 9 to trade encoding time for a smaller file; higher values try harder and take longer.
- 3. For photos, run cwebp with -q followed by a value from 0 to 100. Start high and lower it in small steps only while you see no difference. Add -m 6 to let the encoder spend more time finding a smaller file at the same quality setting.
- 4. As a middle ground for graphics that are too large losslessly, try -near_lossless with a value below 100. Lower values allow more change to pixels in exchange for a smaller file.
- 5. For images with transparency, the alpha channel is kept by default. In lossy mode, -alpha_q controls the quality of the transparency layer separately; leave it at its maximum if edges must stay clean. Add -exact if you need the color values under fully transparent areas preserved.
- 6. Control metadata with -metadata. Use it to keep items such as the color profile or EXIF data, or leave it out to produce a smaller file without them.
- 7. Save each attempt under a new name so you can compare versions and return to the original at any point.
Re-saving an already lossy WebP as lossless will not improve its quality and frequently makes the file bigger. If your only copy is lossy WebP, either accept a small, careful re-encode at a high quality value or keep the file as it is.
Check the output
Compare the file sizes first. If the new file is not smaller, keep the original; a different file format or a stronger lossless effort setting may help, but a larger output is not an improvement.
- Confirm the pixel dimensions and aspect ratio match the original. The webpinfo tool from libwebp, or your image viewer's file information panel, shows the width and height.
- View both images at 100% zoom, side by side, not scaled down. Look at fine textures, gradients such as sky, skin tones, small text and sharp edges, where lossy artifacts appear first.
- If the image has transparency, place it over both a light and a dark background and check the edges for halos or jagged outlines.
- Open the file in every program or browser where it will actually be used, since older software may not display WebP at all or may handle animation and transparency differently.
- If color looks shifted, check whether the original carried a color profile that was removed during compression.
Lossless mode should reproduce the original pixels; you can confirm this by decoding the result with dwebp and comparing it against the source in an image diff tool. Lossy mode always changes pixels, so the goal there is no visible difference at the size the image will be shown, not mathematical identity.
Common problems and next steps
The lossless file is bigger than the original WebP. This usually means the original was lossy. Go back to an uncompressed source, or use a high lossy quality value instead.
Photos show blocky areas or smeared detail. The quality value is too low for that image. Raise it and re-encode from the original source, not from the degraded file.
The background turned white or black. The tool or export setting discarded the alpha channel. Use an encoder that keeps transparency and confirm the source actually contained it.
The file is still too large for its purpose. If the image is displayed smaller than its pixel dimensions, resizing it to the size actually needed, while keeping the aspect ratio, often saves more space than further compression. Do this as a separate, deliberate step and keep the full-size original.
An online compressor's results are hard to judge. Run the same file through a local encoder with known settings and compare both outputs at 100% zoom; this also avoids uploading files whose handling you cannot verify.