One number cannot serve forty images
The usual method is to pick a quality setting once (80, say) and apply it to everything. It is better than quality 100, and it is still wrong, for a reason that follows directly from how the encoder works.
The quality setting scales a quantisation table. It does not target a file size or a visual result. Feed it a photograph of a plain studio background and quality 80 produces a small file that is visually perfect. Feed it a crowd scene in autumn foliage and the same setting produces a large file that still shows artefacts in the leaves, because there is far more fine detail competing for coefficients.
So a fixed quality across a set gives you files that vary wildly in size and vary in how good they look. That is the worst of both.
The honest visual test, done properly
Before any tooling, learn to do this by eye, because it is the ground truth everything else approximates.
- Export the same image at three settings: say 90, 78 and 65.
- Open all three at 100 per cent zoom, not fit-to-window. A scaled view hides artefacts and invents others.
- Flip between them in the same screen position. Do not view them side by side; your eye is far better at spotting change than at comparing two things at once.
- Look where JPEG fails: flat gradients such as sky and studio backdrops, shadow areas, hard edges against flat colour, and any saturated red.
- Take the lowest setting where flipping shows you nothing.
Most photographs land between 72 and 85. Images with large smooth gradients need more; textured images tolerate less than people expect because the artefacts hide in the texture.
Metrics, and what each one is actually measuring
File size difference is not quality. Nor is PSNR, the signal-to-noise figure you will see quoted, which counts every altered pixel equally and therefore rewards blurring.
SSIM and its distance form DSSIM compare local structure (means, variances and correlation over small windows) and correlate much better with what people notice. dssim a.png b.png returns a number where 0 is identical; under about 0.001 is usually invisible on a photograph.
Butteraugli, and the ssimulacra2 score built on similar ideas, model the human visual system more directly, including how much distortion a busy region hides. They are the current best free proxies. Butteraugli returns a distance where lower is better and roughly 1.0 is the threshold of a just-noticeable difference.
The point of a metric is not to replace your eyes. It is to let you run the decision over 400 files instead of 4.
Per-image quality targeting
This is the technique the fixed-slider approach is missing, and free tools do it.
cjpeg with a quality search, or more jpeg-recompress from the jpeg-archive package, encodes at several settings, measures each against the original with a perceptual metric, and keeps the lowest setting that stays under your chosen threshold:
jpeg-recompress --quality medium --method ssim in.jpg out.jpgEvery file comes out at the quality it needs. Across a real catalogue this typically saves 25 to 40 per cent against a fixed quality 82, with no image worse.
avifenc and cwebp both take a quality argument and cwebp -size will target a byte count directly. Squoosh, in a browser, shows the live file size and a slider and lets you do the flip test against the original in the same window, free, with nothing uploaded anywhere.
Budgets, which is how you actually decide
Quality settings are easier to argue about than to justify. Byte budgets are not.
- A full-width photograph on a page: 100 to 300 KB.
- A grid thumbnail: 15 to 40 KB.
- A whole article page, images included: aim under 1 MB, and know that you are choosing when you go over.
- An email: under 100 KB per image, because many clients do not lazy-load and several proxy and re-compress anything larger.
A budget converts an aesthetic argument into arithmetic. If the hero must be 1600 pixels wide and must fit 250 KB, the quality setting is whatever achieves that, and if nothing does, the picture is the wrong picture for the slot.
Two failure modes worth naming
Compressing an already-compressed file. Re-encoding a JPEG you were sent at quality 60 to quality 85 does not improve it; it stores the existing artefacts faithfully in a bigger file. Compress once, from the highest-quality source you have.
Optimising the wrong thing. Shaving 30 KB off a hero that is 2400 pixels wide for an 800-pixel slot is tidying a room that needs a wall moved. Get the dimensions right first; compression is the second-order saving.
Today: take five images from one project, run the flip test on each, and write down the lowest quality that passed. The spread between them is the reason a single number was never going to work.
Every lesson here is open. Your progress is recorded once you pass the Design, before Any Software exam.
Check your understanding
A shop exports 400 product photographs at a fixed JPEG quality of 82. The plain-background shots come out at 90 KB and look perfect; the shots on textured wooden tables come out at 600 KB and still show mush in the grain. What does this tell you about the setting?
Pick the one you would defend. Your answer stays private.
Stuck on something?Ask Neema, your AI tutor