{meta.width} × {meta.height} · {meta.format}
Each example starts from a single source. cachedImage(url) fetches and caches the source photo, then caches every transform below on disk — so the first request
does the work and later requests (even after a restart) skip the fetch, decode, and encode. The chain mirrors Bun.Image's API; every snippet reuses this
img.
.metadata() reads dimensions and format from the header without decoding pixels:
{meta.width} × {meta.height} · {meta.format}
The same source into a 240×240 box. fit: 'fill' stretches to the exact box; fit: 'inside' preserves aspect ratio and fits within it:
fit: 'fill'fit: 'inside'
filter picks the resampling kernel. To make it visible, each image is shrunk to 56px then enlarged to 240px — 'nearest' keeps hard pixels, the default
'lanczos3' interpolates smoothly:
filter: 'nearest'filter: 'lanczos3'.rotate(deg) turns the image clockwise in multiples of 90:
rotate(90)rotate(180)rotate(270).flip() mirrors vertically (about the x-axis); .flop() mirrors horizontally:
flip()flop().modulate() adjusts brightness and saturation (1 = unchanged):
saturation: 0brightness: 1.5saturation: 2
The same 300px image encoded three ways, with byte sizes. Bun.Image can also encode avif() and heic(), but those go through the OS
backend and are only available on macOS and Windows:
{label} · {kb(out.size)}
png({'{'} palette: true }) quantizes to a ≤256-colour indexed PNG — typically several times smaller than truecolor:
palette: true, colors: 32, dither: true · {kb(pngPalette.size)}
The same JPEG at two quality levels — the trade-off between artefacts and bytes:
quality: 20 · {kb(qLow.size)}quality: 85 · {kb(qHigh.size)}
.placeholder() returns a ThumbHash-rendered blur as a data: URL (~400–700 bytes, no client decoder) — inline it as an instant low-quality preview before
the real image loads:
placeholder()
jpeg({'{'} progressive: true }) encodes a progressive JPEG that paints coarse-to-fine as it downloads — visually identical once loaded, but it appears sooner over a
slow connection:
progressive: true · {kb(progressive.size)}