Documentation menu
Docs › Delivery
Image optimisation
Cache.bz can transform images on the way through the edge: resize, crop, change quality and convert to modern formats, with the result cached like any other object.
Enabling transforms
Turn on image optimisation for the paths that hold images. Transforms are then requested with query parameters on the original URL.
[[rules]]
match = ["/images/*", "/uploads/*"]
images = { enabled = true, formats = ["avif", "webp"], max_width = 3000 }Parameters
| Parameter | Example | Description |
|---|---|---|
w, h | w=800 | Target width and height in pixels. |
fit | fit=cover | contain, cover, crop, scale-down or pad. |
q | q=70 | Quality from 1 to 100. Default 82. |
fm | fm=auto | auto, avif, webp, jpeg or png. |
dpr | dpr=2 | Device pixel ratio multiplier, 1 to 3. |
g | g=face | Crop gravity: center, north, south, east, west, face, auto. |
<img src="/images/hero.jpg?w=1200&fm=auto&q=75"
srcset="/images/hero.jpg?w=600&fm=auto 600w,
/images/hero.jpg?w=1200&fm=auto 1200w,
/images/hero.jpg?w=2000&fm=auto 2000w"
sizes="(max-width: 700px) 100vw, 1200px"
alt="Our product on a desk" width="1200" height="675">Automatic format
With fm=auto the edge picks the best format the browser announces in its Accept header: AVIF, then WebP, then the original format. The format is part of the cache key, so each variant is cached separately.
Billing and caching
A transform is billed once per unique combination of source image and parameters per month, however many times it is served. Transformed images are cached at the edge and in the shield tier, and are purged together with their source image.
Source images up to 70 MB and 100 megapixels. Output up to 8,192 pixels on the longest side. Animated GIFs are converted to animated WebP when fm=auto.