Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

PNG, JPG or WebP? A developer's rule of thumb for picking image formats

Most image-format bugs I see in code review aren't exotic. A logo ships as a 900 KB JPG with fuzzy edges. A hero photo ships as a PNG that weighs more than the rest of the page combined. A product cut-out loses its trans

Most image-format bugs I see in code review aren't exotic. A logo ships as a 900 KB JPG with fuzzy edges. A hero photo ships as a PNG that weighs more than the rest of the page combined. A product cut-out loses its transparency and shows up on a white box over a dark theme. All three come from the same gap: picking a format by habit instead of by what the pixels are.

Here's the rule of thumb I actually use.

First, know what you're compressing

A 1920×1080 image is 2,073,600 pixels. Stored raw with an alpha channel (4 bytes per pixel), that's 8,294,400 bytes — about 8.3 MB before any compression. Every format below is a different strategy for shrinking that number, and each one is good at a different kind of image.

  • PNG is lossless. It reproduces every pixel exactly and supports full alpha transparency. It compresses well when the image has large flat areas and repeated patterns — UI, text, diagrams, icons.
  • JPG is lossy. It throws away detail the eye is bad at noticing, which works beautifully on photos with gradients and noise. It has no alpha channel at all.
  • WebP can do both: a lossy mode for photos and a lossless mode for graphics, with alpha in either. For most web delivery it's the format to reach for first.

The decision, in three questions

1. Does it need transparency? If yes, JPG is out. Use PNG for a source asset you'll keep editing, WebP for what you actually serve.

2. Is it a photo or a graphic? Photos (people, landscapes, product shots on a background) → JPG or lossy WebP. Graphics (screenshots, logos, charts, anything with sharp text) → PNG or lossless WebP. JPG's compression smears hard edges, which is why a screenshot saved as JPG gets that halo of artifacts around every letter.

3. Where does it end up? If an upload form, email client or legacy CMS only accepts JPG, the decision is made for you — convert and move on.

What happens when you convert PNG to JPG

Two things change, and both are worth knowing before you script it.

First, the alpha channel has to go somewhere. JPG can't store it, so transparent pixels get flattened onto a solid background — usually white. A logo designed for a dark header will suddenly sit on a white rectangle. If that matters, don't convert to JPG; convert to WebP and keep the alpha.

Second, quality is a dial, not a switch. Around 85–90 is the usual sweet spot for photos: visibly identical, much smaller. Pushing below ~70 starts to show blocky artifacts in skies and skin tones. And every lossy re-save compounds the damage, so keep your lossless original and always export from it.

Common mistakes

  • Serving PNG photos because "PNG is higher quality." Lossless doesn't mean better-looking on a photo — just heavier.
  • Saving screenshots and UI as JPG and wondering why the text looks dirty.
  • Converting a transparent asset to JPG without noticing the new white background.
  • Re-compressing the same JPG over and over instead of exporting once from the source.

I wrote a longer walkthrough of the PNG-versus-JPG trade-off — when a conversion is worth it and when to leave the file alone — on the Toolonium blog. When you just need the conversion done, there's a free PNG to JPG converter that runs in your browser, so the image never leaves your machine.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.