Skip to content
hateitall

How to compress an image to a target file size

There is no quality percentage that makes every image exactly 1 MB or 100 KB. A reliable target-size workflow measures real encodes, preserves the best result under the limit, and tells you when resizing is necessary.

8 min readWritten and tested by HateItAll engineeringLast reviewed August 5, 2026

Why one quality setting cannot guarantee one file size

Image size depends on more than width and height. A clean illustration, a noisy night photo, and a screenshot can contain the same number of pixels but compress very differently. Fine texture, sensor noise, text edges, gradients, transparency, metadata, and the chosen format all change how many bytes the encoder needs.

That is why advice such as 'use quality 80 for 1 MB' is only a starting guess. Browser encoders accept a quality value for lossy formats such as JPEG and WebP, but the result is a real encoded blob whose size must be measured. The same quality value can produce very different byte counts for different images.

A measured target-size search

A dependable compressor tests candidate quality values and measures each output. If a candidate is too large, it searches lower; if it fits, it keeps that result and searches higher. The goal is not to land on the target byte exactly. It is to preserve the highest tested quality that stays at or below the cap.

The search must use the actual output bytes rather than an estimate, and it should reopen the chosen file to confirm that it still decodes. HateItAll follows that pattern locally and shows the measured source and output sizes before download.

  • Start from the original image for each attempt
  • Choose JPEG or WebP when a strict byte target matters
  • Measure every encoded candidate instead of trusting a fixed percentage
  • Keep the highest-quality result that fits below the limit
  • Decode the final bytes again before offering the download

When quality reduction is not enough

If the lowest acceptable quality is still too large, reduce pixel dimensions. Downscaling removes data before encoding, so the remaining bitrate can describe each pixel more cleanly. Match the dimensions to the destination: an application thumbnail does not need every pixel from a modern phone camera.

Crop irrelevant borders before resizing when possible. For screenshots, inspect small text after every change. JPEG may introduce halos around hard edges; WebP can be a better compromise when the destination accepts it. PNG is lossless and does not expose the same quality control, so a strict target may require converting formats or reducing dimensions.

Understanding KB, MB, and the final check

Upload forms are not consistent about units. Some treat 1 MB as 1,000,000 bytes; others use 1,048,576 bytes. A result near the boundary can therefore be rejected even when its file manager label looks correct. Leave a small margin when the receiving system does not publish its exact rule.

After compression, inspect the regions that matter—faces, small lettering, signatures, and gradients—at normal viewing size and at 100 percent. Meeting the cap is only half the job. The useful result is the smallest change that satisfies the limit without damaging the content people need to read.

Sources and standards

We used the following format and browser documentation when reviewing this guide:

Do it locally

The tools this guide refers to — all running in your browser, nothing uploaded.

Quality slider and target-size search with side-by-side comparison. Metadata is stripped by default.

PNG · JPEG · WebPJPEGLight on device

Compress many JPG, PNG, and WebP images in one go with a shared quality or per-image target size, then download them as a zip.

PNG · JPEG · WebPJPEGModerate on device

Resize by pixels, percentage, or platform preset with contain/cover/stretch modes and upscale warnings.

PNG · JPEG · WebPPNGLight on device

PNG, JPEG, and WebP conversion with explicit transparency handling and per-file batch results.

PNG · JPEG · WebP +PNGLight on device