Sub topic 4
JPEG: photographs and complex images
This chapter assumes you know what pixels and display density are, and the difference between lossy and lossless compression. It also assumes you can export from a design tool such as Figma or Photoshop.
What JPEG does well
JPEG is a lossy format built for photographs. A photo has smooth gradients, fine texture, and millions of slightly different colors. JPEG discards detail the eye barely notices, so these images shrink a lot. A photo that is 4 MB as a PNG is often under 300 KB as a JPEG with no obvious difference.
JPEG works on small blocks of pixels. It also stores color at lower resolution than brightness, a step called chroma subsampling. Human eyes are more sensitive to brightness, so this saves space at little visual cost.
Where JPEG fails
JPEG has three limits that cause most export mistakes:
- No transparency. Transparent areas are filled with a solid color, usually white or black.
- Artifacts on sharp edges. Text, thin lines, and flat color next to high contrast produce fuzzy halos and blocky noise around the edges. Use PNG or SVG for those.
- Generation loss. Each time you re-save a JPEG, it loses more detail. Keep an original (a layered file or PNG) and always export from that, never from a previous JPEG.
Exporting a JPEG
The quality setting runs from 0 to 100. It is not a percentage of the original. It is a scale that trades file size against artifacts. The command below resizes to 1600 pixels wide, strips metadata, and saves at quality 80:
magick hero.png -resize 1600x -strip -quality 80 hero-1600.jpgYou can also ask for a progressive JPEG. It loads as a blurry full image that sharpens, instead of drawing from top to bottom:
magick hero.png -resize 1600x -strip -interlace Plane -quality 80 hero-1600.jpgChoosing a quality value
Most photos look fine between 70 and 85. Above about 90, file size climbs quickly with little visible gain. Below about 60, banding in skies and blocky patches become easy to see.
To choose a value, export the same image at 60, 75, and 90. Zoom to 100% and compare them. Look at areas with gradients and sharp edges, because artifacts appear there first. Pick the lowest value that still looks clean.
Common errors
- Exporting at a much larger size than the image is displayed. Resize first, then compress.
- Saving a logo or icon as JPEG. Vector or lossless formats suit those.
- Re-exporting from an already compressed JPEG.
- Leaving metadata in place, which adds size and can expose camera or location data.
Exercise
A designer exports a photo with a transparent background as a JPEG and sees a white box around the subject in the browser. Why does this happen, and what are two ways to fix it?
Show answer
JPEG does not support transparency, so the transparent area was filled with white. One fix is to export as PNG, WebP, or AVIF, which support transparency. The other is to keep the JPEG but give the photo a background that matches the page, so the fill is not noticeable.