DEV Community

GoToolsOnline
GoToolsOnline

Posted on

Why your resized image looks blurry: resampling and aspect ratio, explained

Resizing an image sounds like one operation, but there are two separate decisions hiding in it, and getting either wrong produces the classic "why does this look soft / squashed?" result.

1. Aspect ratio: stretch, fit, or crop

An image has a shape (width ÷ height). If you resize a 4000×3000 photo (4:3) to 1080×1080 (1:1) by typing both numbers, the pixels get squeezed horizontally. There are really only three honest choices:

  • Fit: scale until one side matches, keep the shape. You get 1080×810, not a square.
  • Crop then scale: cut a 3000×3000 square from the centre, then scale to 1080×1080.
  • Pad: scale to fit, then add bars to fill the square.

Stretching is almost never what anyone wants.

2. Resampling: how new pixels are invented

When you shrink 4000 px to 1080 px, each output pixel has to summarise several input pixels. Common filters:

  • Nearest neighbour: picks one pixel. Fast, but jagged; only good for pixel art.
  • Bilinear: averages 4 neighbours. Fine for small changes, slightly soft for big reductions.
  • Bicubic / Lanczos: look at more neighbours and keep edges crisper. Lanczos is a good default for big downscales of photos.

In the browser, canvas.drawImage with ctx.imageSmoothingQuality = "high" gives decent results; for large reductions, scaling down in steps of about half each time can look sharper than one big jump in some browsers.

3. Upscaling can't add detail

Enlarging a 400 px image to 2000 px just spreads the same information over more pixels. Classic resizers will look soft; AI upscalers guess detail, which can look great or invent things that weren't there.

4. Display size vs file size

For the web, resize to roughly the size the image is shown (about 2× for high-density screens), then compress. Compressing a 4000 px image you then display at 800 px wastes most of the bytes.

Quick checklist

  • Decide fit vs crop before typing numbers.
  • Downscale with a good filter (Lanczos/bicubic).
  • Don't upscale and expect sharpness.
  • Resize first, compress second.

Disclosure: I run GoToolsOnline. Its free image resizer sets an exact width and height (up to 4096 px) or centre-crops to 1:1, 4:3, 16:9, 3:4 or 9:16 first: https://gotoolsonline.com/tools/image-resize

Top comments (0)