Choosing an image format: PNG, JPEG, WebP, AVIF, SVG, TIFF and BMP
How to pick the right image format for photographs, UI screenshots, transparent icons, vector illustrations, and print archival—and what edge cases to include in your image upload test plan.
1. Decision matrix by image content and delivery target
No single image format wins across every use case. Photographic camera images have continuous tone gradients and sensor noise that compress poorly in lossless dictionary coders, whereas flat-color UI graphics, diagrams, and text screenshots develop unsightly ringing artifacts when compressed with lossy 8×8 DCT blocks.
| Format | Compression | Transparency | Animation | Color depth | Best use case |
|---|---|---|---|---|---|
| JPEG (.jpg) | Lossy DCT | No | No | 8-bit RGB / CMYK | Universal photography & email attachments |
| PNG (.png) | Lossless DEFLATE | 8/16-bit RGBA | Via APNG | 1/8/16-bit per channel | Screenshots, UI assets, alpha cutouts, master graphics |
| WebP (.webp) | Lossy VP8 & Lossless VP8L | 8-bit Alpha in both modes | Yes | 8-bit RGBA / YUV | All-purpose web delivery (25–35% smaller than JPEG/PNG) |
| AVIF (.avif) | Lossy & Lossless AV1 | 8/10/12-bit Alpha | Yes | 8/10/12-bit HDR & SDR | High-efficiency hero photos & HDR web imagery |
| SVG (.svg) | XML Vector (gzip/brotli) | Full RGBA & masks | CSS / SMIL | Resolution-independent | Logos, icons, charts, diagrams at any DPI |
| TIFF (.tiff) | Uncompressed, LZW, ZIP, JPEG | Yes | Multi-page | 1 to 32-bit RGB/CMYK | Print publishing, multi-page document scans, GIS GeoTIFF |
| BMP (.bmp) | Uncompressed DIB | 32-bit BGRA | No | 1 to 32-bit | Zero-CPU-decode embedded bitmaps & Windows GDI tests |
2. Security and parser pitfalls when accepting user-uploaded images
- SVG is an executable XML document when opened directly: Unlike raster formats (PNG, JPEG, WebP, AVIF), an SVG file is an XML document that can contain inline
<script>tags,onloadevent handlers, and external<image xlink:href (external URI)>references. If a user uploads an SVG and your server serves it from the same origin withContent-Type: image/svg+xml, opening that image URL directly in a browser tab executes any embedded JavaScript (Stored XSS). Always sanitize uploaded SVGs (e.g., with DOMPurify), serve user uploads from an isolated sandbox domain, or rasterize untrusted uploads to PNG/WebP. - Decompression bombs (pixel flood attacks): A solid-color
25000×25000PNG compresses down to less than 150 KB on disk because DEFLATE compresses repeating zero rows at over 1000:1. However, decoding that image into a 32-bit RGBA bitmap allocates25000 × 25000 × 4 = 2.5 GBof RAM. Always inspect the width and height from the 24-byte PNGIHDRchunk (bytes 16–23) before allocating a pixel buffer. - EXIF Orientation and CMYK color spaces: Test your image resizer against all 8 EXIF Orientation flags and our CMYK JPEG fixture on Media Edge Cases.