Skip to main content

Change Image Quality

About the quality feature

What is it? Quality reduces the quality level of JPG and PNG images. Works with compression, resize, or crop.

LevelFile SizeVisual Impact
High (95%)813 KBOriginal
Medium (80%)~650 KBMinimal difference
Low (65%)~400 KBSlight reduction
Custom (50%)~300 KBNoticeable

Enable quality

Quality is included in the Image Stack service. Configure via environment variables or query parameters.

Via environment variables

QUALITY_PRESET=high       # 95% (default)
QUALITY_PRESET=medium     # 80%
QUALITY_PRESET=low        # 65%
QUALITY_PRESET=custom:75  # 1-100

PNG_LOSSLESS=true   # PNG→WebP: lossless conversion (recommended)
PNG_LOSSLESS=false  # PNG→WebP: lossy conversion with quality

Via query parameters

image.jpg?quality=80&fmt=webp
image.jpg?quality=76&crop=200,200

Where quality value is 1-100.

Quality behavior by format

FormatQuality SupportNotes
JPEG✅ Fully SupportedQuality parameter works as expected
WebP✅ Supported (1‑93)Values above 93 are clamped to 93 to keep libwebp stable under WASI.
PNG (no conversion)❌ IgnoredAlways lossless, quality ignored
PNG→WebP (PNG_LOSSLESS=true)❌ IgnoredLossless conversion, quality ignored
PNG→WebP (PNG_LOSSLESS=false)✅ AppliedLossy conversion, quality applied

Usage examples

<!-- JPEG with quality -->
<img src="photo.jpg?quality=80" alt="Photo" />

<!-- WebP (quality capped at 93) -->
<img src="photo.jpg?quality=95&fmt=webp" alt="Photo" />

<!-- Resize + quality -->
<img src="photo.jpg?width=800&quality=80" alt="Photo" />

<!-- Crop + quality -->
<img src="photo.jpg?crop=16:9&quality=80" alt="Photo" />

<!-- Full transformation -->
<img src="photo.jpg?width=1200&crop=16:9&quality=85&fmt=webp" alt="Photo" />

Check HTTP headers

curl -I https://your-cdn.com/image.jpg?quality=80&fmt=webp

Expected headers:

  • Content-Type: image/webp
  • X-Img-Operations: conversion

Limitations

WebP quality clamp

  • WebP lossy encoding now runs via libwebp inside WASI, but values above ~93 frequently exhaust linear memory.
  • Requests above 93 are automatically clamped to 93 and a warning is logged.
  • When PNG_LOSSLESS=true, PNG inputs still take the pure-Rust lossless path, so quality is skipped in that specific case.

See limitations.md for details.

QUALITY_PRESET=high
PNG_LOSSLESS=true
CONVERT_TO_WEBP=true

See also