Sub topic 13
Setting compression quality
This chapter assumes you know the difference between lossy and lossless compression, can pick a format for an image, and already know the export dimensions. It covers how to choose a quality setting once those decisions are made.
What the quality number means
Lossy formats such as JPEG, WebP, and AVIF take a quality setting, usually 0 to 100. A lower number discards more detail and produces a smaller file. The number is not a percentage of anything. Quality 80 in JPEG and quality 80 in WebP give different results and different file sizes, because each encoder uses the number differently. Compare results in each format separately.
PNG and SVG have no quality slider. PNG is lossless, so you reduce its size by lowering the dimensions or the number of colors. Lossless WebP works the same way.
Find the setting by comparing
There is no single correct quality value. A photo with soft gradients and a photo of a brick wall need different settings. Use this method:
- Export the image at a high quality, such as 90, as a reference.
- Export again at 80, 70, and 60.
- View each file at 100% zoom, at the size it will appear on the page.
- Pick the lowest quality where you cannot see a difference from the reference.
- Record the file size of the version you chose.
Look at the places where lossy compression fails first: smooth gradients such as skies show banding, text and sharp edges show fuzzy halos, and faces show blocky skin.
Typical starting points
These are starting values, not rules. Adjust them with the comparison method.
| Format | Starting quality | Notes |
|---|---|---|
| JPEG | 75 to 85 | Below about 60, blocky artifacts are common. |
| WebP (lossy) | 75 to 80 | Often 20 to 30 percent smaller than JPEG at similar looks. |
| AVIF | 55 to 70 | Its scale runs lower, so a 60 can look like a JPEG 80. |
Export from the command line
Command-line tools make the comparison repeatable. This example resizes a PNG to 1600 pixels wide, strips metadata, and writes a JPEG at quality 80. It then writes a lossy WebP at quality 80.
magick hero.png -resize 1600x -strip -quality 80 hero-1600.jpg
cwebp -q 80 hero-1600.png -o hero-1600.webpRun the same commands with -quality 70 and -q 70 and compare the outputs next to each other.
Common mistakes
- Using one quality value for every image in the project.
- Judging quality while zoomed out, which hides artifacts.
- Exporting at quality 100, which gives a large file with no visible gain over 85 or so.
- Forgetting to compare file sizes, so a "better" setting costs far more bytes than it is worth.
Exercise
You export a photo as a JPEG at quality 90 (420 KB), 80 (210 KB), and 70 (160 KB). At 100% zoom, quality 80 looks identical to 90, and 70 shows banding in the sky. Which setting do you ship, and why?
Show answer
Ship quality 80. It matches the quality 90 reference visually and is half the size. Quality 70 saves another 50 KB but shows visible banding, so it fails the "no visible difference" test.