Choosing Image Formats: WebP and AVIF Compression, the Transparency Cost, and Compatibility Edges

Four Formats: Compression Method Decides the Use Case

Format Compression Alpha Best for
PNG Lossless (DEFLATE) Yes, 8/24/32-bit Icons, screenshots, text art, transparency
JPEG Lossy (DCT) No Photos, gradients, backgrounds
WebP Lossy or lossless Yes The general default
AVIF Lossy or lossless Yes Maximum compression, progressive enhancement

The distinction is one sentence: lossless (PNG, WebP lossless) restores every pixel and suits flat colour and line art; lossy (JPEG, WebP lossy) discards high-frequency detail the eye barely notices, shrinking a photograph to a tenth of its size at the cost of irreversible detail loss.

That also explains why PNG resists compression: the lossless algorithm is nearly useless on gradients and noise, so a photo saved as PNG often runs close to ten times the JPEG size. Pick the wrong format and every compression setting afterwards is wasted effort.

Selection: One Table, One Test

The test is a single question: does the image contain large areas of contiguous flat colour? Yes → PNG (or smaller still, SVG); no → JPEG, WebP or AVIF.

Use Recommended Why
Website icons SVG first, PNG fallback Vector scales losslessly at any size
UI screenshots PNG or lossless WebP Text must stay crisp
Content photos WebP with AVIF enhancement Broad support plus best compression
Decorative backgrounds JPEG or lossy WebP No transparency needed
Images needing alpha WebP or AVIF The only formats combining alpha with real compression
Simple looping animation Animated WebP 30–50% smaller than GIF
Complex frame-by-frame animation Keep GIF or use video WebP inter-frame prediction fails
Desktop app icons ICO The Windows convention

How far flat colour compresses: a 512x512 icon can be 3KB as PNG, while the same pixel count of photographic detail will barely move. The in-site image compressor applies this test to choose lossless or lossy.

Transparency and Animation: Two Costs

The cost of alpha. PNG in 8-bit mode offers only fully transparent or fully opaque; 32-bit RGBA adds partial alpha and a larger file. JPEG has no alpha channel at all — so a black background after converting a transparent PNG is not a bug, it is the format having nowhere to store alpha, leaving the tool to drop it or fill a solid colour. Keep PNG when transparency matters, or switch to WebP/AVIF; if you need compression without alpha, drop PNG to 8-bit indexed colour.

The cost of animation. Converting an animated GIF to WebP often makes it bigger, and inter-frame prediction is the reason: GIF applies LZW to a fixed palette with no differencing between frames, so size stays predictable; WebP's prediction works well on translation and fades, but fails when most of the frame changes and then stores whole frames. Measure before committing — simple loops (loaders, emoji) typically shrink 30–50%, while hand-drawn or particle animation should stay GIF or move to video. Trim dead frames with the GIF cropper.

Conversion and Size: Get It Right in One Pass

Lossy degradation is cumulative, so the whole flow is three steps:

  1. Keep a lossless master (PNG or the original);
  2. Convert once from the master at quality around 90;
  3. Do every resize, watermark and crop on the master, never on an already compressed copy.

The anti-pattern is JPEG → watermark → save JPEG → resize → save JPEG: four lossy steps, and the degradation becomes visible.

There is a quieter trap too: EXIF orientation can be dropped. A phone photo shot in portrait relies on the EXIF rotation tag to display upright, and some converters leave it lying down. Burn the rotation into pixels before processing and the result no longer depends on the toolchain.

Size works the same way: resize to the display size before compressing. If the slot is 400px wide and the source is 4000px, compressing the original wastes 90% of the pixels. Always resize to target, then convert and compress once — never outsource the downscale to the browser.

Reproducible Results

Export one screenshot as PNG, WebP and JPEG, then compare size and text edges: PNG is largest with the crispest text, WebP is clearly smaller with differences hard to see, and JPEG is smallest but shows ringing artefacts around glyphs. Then run the same phone photo through the image compressor: PNG barely moves while JPEG reaches a tenth of the size — direct evidence that format choice comes before compression settings.

Frequently Asked Questions

Should I pick WebP or AVIF?

Default to WebP, and reach for AVIF only when you need the last drop of compression. WebP's support is now close to universal (Chrome, Firefox, Edge and Safari 14+), and it encodes an order of magnitude faster than AVIF. AVIF is another 20–30% smaller at equal quality, but encoding is 10–20x slower and compatibility gaps remain on some platforms, notably older Android and certain mini-program containers. The pragmatic approach is WebP as the workhorse, AVIF as progressive enhancement — serve all three sources in a <picture> element and let the browser choose.

Why does PNG to JPEG shrink the file so much?

Because the two use entirely different compression principles. PNG uses DEFLATE lossless compression with run-length encoding on pixels; it does well on flat colour areas but performs poorly on gradients and photographs, where every pixel differs slightly. JPEG uses DCT lossy compression, splitting the image into 8x8 blocks, applying the discrete cosine transform and discarding high-frequency detail the eye barely perceives — excellent for photographs, at the cost of permanently losing detail that accumulates with every re-encode. The correct pattern is a single conversion, never repeated: convert once at the highest quality (90 or above) and do all subsequent compression and resizing from that master.

Why does my PNG stay large no matter how much I compress it?

Because PNG is unsuited to photographs by nature. Its lossless algorithm is nearly ineffective on gradients and noise — a 4000x3000 phone photo can be 8MB as PNG and 1MB as JPEG. The test is simple: look for large areas of contiguous flat colour. Screenshots, icons, buttons and text belong in PNG (or even smaller as SVG); photographs, gradients and noise belong in JPEG, WebP or AVIF. A second lever is reducing the colour count: an image with a few hundred colours converts to indexed (palette) PNG and saves 30–60%. A compressor tool picks the right strategy based on image type.

← Back to Blog