Images 3 min read English and Simplified Chinese

How to compress an image to a target file size

A form that insists on 200 KB or a marketplace that rejects files above a megabyte leaves you with a specific number to reach. Getting there is mostly about the order in which you make changes: pixels first, then compression, then a final check on the real file.

Do not start by re-compressing

Compression removes detail in ways the eye may or may not notice. Resizing removes pixels, which is a much clearer decision: a 4000-pixel-wide photo displayed in a 900-pixel column carries four to five times more pixels than the screen can show. Shrinking it first usually saves more size, with less visible damage, than pushing the quality slider down on the full-size image.

Only change dimensions the destination actually needs. An ID photo, a print file or an archive image may be limited by its pixel size instead of its byte size, and shrinking it would make it unusable even if the bytes look right.

Understand what a target size can promise

Tools that compress to a target file size search for a quality that lands near the number. The search is iterative, so the output may end up slightly above or below the target, and an aggressive target on a detailed image can look much worse than the preview suggests.

The only reliable test is the reported output size next to a look at the result at the size it will be viewed. Compare those together; a file that hits 198 KB but turns skin and fine text into mush has not solved the problem.

A workable order

  • Note the destination limits: maximum bytes, maximum pixel width and height, and whether it accepts WebP
  • Resize only if the destination will display the image smaller than it is today
  • Choose a format the destination accepts; WebP often beats JPG for photos at similar quality
  • Compress towards the byte limit, then download and open the result at its real display size
  • If quality is not enough, move to the closest acceptable step: slightly smaller dimensions or a better format, not a lower number blindly

When it still will not fit

If a photo with fine detail cannot reach the target without visible damage, the limit is probably wrong for the content. Ask whether the destination really needs that size, or whether a different format or a smaller display dimension is acceptable.

For screenshots and flat graphics, compression is often the wrong lever: the content is text and sharp edges, which look worst under heavy JPG compression. Converting to PNG, or reducing dimensions, tends to give better results for the same byte budget.

Try it here