Lossy vs Lossless Compression
Two fundamentally different approaches to reducing image file sizes. Understand the principles, tradeoffs, and when to use each compression method.
Overview
Digital image compression falls into two broad categories: lossy and lossless. These two approaches embody fundamentally different philosophies, and each has its own ideal use cases.
- Lossy compression: Discards information that is difficult for the human visual system to perceive, dramatically reducing file size. The original cannot be reconstructed.
- Lossless compression: Finds and eliminates statistical redundancy without discarding any data. The original can be perfectly reconstructed.
The choice between the two depends on your priorities: file size vs perfect fidelity. In practice, most workflows use a combination of both depending on the content type.
Lossy Compression
Lossy compression leverages the Human Visual System (HVS) to determine what information can be safely removed. The key insight is that human perception has well-known limitations that can be exploited.
How It Works
- Perceptual modeling: The encoder analyzes which parts of the image the human eye is least sensitive to. High-frequency details, subtle color variations, and information in busy textures are all candidates for removal.
- Transform coding: The image data is transformed from the spatial domain to the frequency domain (e.g., DCT in JPEG, prediction in VP8/WebP). This concentrates the visually important information into a few key coefficients.
- Quantization: The transformed coefficients are rounded to reduce precision. This is the irreversible step where data is permanently lost.
- Entropy coding: The quantized data is further compressed using lossless techniques (Huffman coding, arithmetic coding) to minimize the final file size.
Lossy compression is irreversible. Once an image is saved with lossy compression, the discarded information is gone forever. Always keep your original files and treat lossy exports as final outputs.
Common Artifacts
- Blocking: Visible grid patterns at block boundaries (common in JPEG at low quality).
- Ringing: Halo-like artifacts around sharp edges.
- Color banding: Smooth gradients break into visible steps.
- Mosquito noise: Shimmering artifacts around edges in video-derived codecs.
Lossless Compression
Lossless compression guarantees perfect reconstruction of the original image. Every single pixel is preserved exactly as it was before compression. The compression ratio is lower, but no information is sacrificed.
How It Works
- Prediction: Each pixel is predicted from its neighbors. Only the difference (residual) between the prediction and the actual value needs to be stored, and these residuals tend to be small numbers that compress well.
- Entropy coding: The residuals and other data are encoded using statistical methods such as Huffman coding, arithmetic coding, or LZ77-based dictionary methods. Frequently occurring patterns receive shorter codes.
- Run-length encoding (RLE): Sequences of identical values (common in screenshots and graphics) are stored as a single value plus a count.
- Dictionary coding: Repeated sequences of data are replaced with references to a dictionary, effectively deduplicating the data stream.
Lossless compression works best on images with large uniform areas and sharp edges, such as screenshots, diagrams, and logos. Photographs with complex textures compress poorly in lossless mode because there is less statistical redundancy to exploit.
Core Comparison
| Feature | Lossy | Lossless |
|---|---|---|
| Data loss | Yes (irreversible) | No (perfect reconstruction) |
| Compression ratio | High (10-50x typical) | Moderate (2-5x typical) |
| File size | Much smaller | Larger |
| Visual quality | Slight degradation (often imperceptible) | Identical to original |
| Re-editing safety | Quality degrades with each save (generation loss) | No quality loss on re-save |
| Best for | Photos, natural images | Screenshots, text, logos, diagrams |
| Key principle | Human visual system modeling | Statistical redundancy removal |
Format Support
| Format | Lossy | Lossless | Transparency | Animation |
|---|---|---|---|---|
| JPEG | Yes | No | No | No |
| PNG | No | Yes | Yes | No |
| GIF | No | Yes (256 colors) | Yes (1-bit) | Yes |
| WebP | Yes | Yes | Yes | Yes |
| AVIF | Yes | Yes | Yes | Yes |
| BMP | No | Uncompressed | Yes | No |
Decision Guide
Choosing between lossy and lossless depends on the content type and intended use. Here are practical guidelines:
Use Lossy Compression For
- Photographs: Natural images with complex textures and gradients. Lossy compression excels here because the human eye is tolerant of subtle quality loss in these contexts.
- Web images: Banners, hero images, product photos. Page load speed is critical, and the smaller files justify minor quality tradeoffs.
- Social media: Platforms often re-compress uploads anyway, so starting with a high-quality lossy image is the pragmatic choice.
Use Lossless Compression For
- Screenshots: Text and UI elements have sharp edges that lossy compression distorts. Lossless preserves every pixel.
- Logos and icons: Brand assets that require precise colors and clean edges.
- Diagrams and charts: Technical illustrations with text labels, thin lines, and flat color areas.
- Medical and scientific images: Where every pixel may carry diagnostic or analytical significance.
- Archival storage: When you need to preserve the original for future editing or reference.
Rule of thumb: If the image came from a camera, use lossy. If it was generated by a computer (screenshot, UI, diagram), use lossless.
E-ink Considerations
E-ink displays have unique characteristics that affect how compression choices should be made:
- Limited grayscale levels: Most E-ink displays show only 16 levels of gray. This means the image is already heavily quantized by the display itself, reducing the benefit of lossless compression.
- No color (typically): Since most E-ink devices are monochrome, converting to grayscale before compression significantly reduces file size regardless of the method chosen.
- Lossy is usually fine: Because the E-ink display cannot reproduce the subtle details that lossy compression removes, quality loss from JPEG or lossy WebP is essentially invisible on these screens.
- Device compatibility: JPEG has near-universal support on E-ink devices. WebP support varies by device manufacturer. PNG is safe but produces larger files.
For E-ink wallpapers, lossy JPEG at quality 85 is an excellent default. The 16-level grayscale limitation of E-ink displays means that any quality loss from JPEG compression is completely imperceptible on the device.
CropCrop Export Guide
CropCrop lets you choose your export format and compression settings. Here is how to make the best choice:
- For photographs and camera images: Export as JPEG with quality 85-90. This provides an excellent balance of quality and file size.
- For screenshots or text-heavy images: Export as PNG for perfect pixel preservation, or use lossless WebP for smaller files.
- For images with transparency: Export as WebP (lossy or lossless) or PNG. JPEG does not support transparency.
- For E-ink wallpapers: Apply the grayscale filter first, then export as JPEG at quality 85. This maximizes device compatibility and minimizes file size.
- For web publishing: Lossy WebP at quality 80-85 offers the best file-size-to-quality ratio for modern browsers.
CropCrop processes images entirely on the client side. Your original images are never uploaded to a server, so you can safely edit private or sensitive photos.