Drop the originals next to the post and refer to them in Markdown. coffer resizes every image a post uses, publishes the small versions and never the original. This page describes what the build makes, what the pages look like and how to tune it. Which location and camera metadata an image may publish is decided by a policy described in Location and camera metadata; What the files carry below says what the build then writes.
Using Images


- The text in the brackets is the alt text. Write it for someone who cannot see the picture. An image without alt text still builds and appears in the build report as a warning with the file, line and column; an image that is purely decoration can keep its empty alt text and its warning.
- The optional quoted text after the address is the caption. An image that stands alone in its paragraph becomes a
<figure>with the caption in a<figcaption>; without a caption there is no<figcaption>. The caption is inline Markdown:_emphasis_,**strong text**,`code`and~~strikethrough~~keep their markup in the<figcaption>and in feeds. A link, an image or raw HTML in a caption is shown as its text, and the image viewer, the list of images and the title of a carousel slide use the caption as plain text. - The address is relative to the Markdown file and must stay inside the content directory, so a folder post can keep its pictures beside
index.md, and several posts can share a folder such ascontent/journal/photos/. An address that starts with/(a file of the site’s assets) or is a URL (https://...) is not an original; it is left exactly as written, without a size. - Accepted inputs are JPEG, PNG, WebP and HEIC (judged by the file’s contents as well as its extension; see HEIC photos from phones). Another format, such as GIF or SVG, fails the build with the file, line and column; a file that cannot be decoded does too.
A post’s cover (front matter) is processed the same way; its 1200 pixel WebP variant is the preview image of the post (see SEO and link previews).
HEIC Photos from Phones
iPhones and many Android phones save photos as HEIC (.heic or .heif). You can drop those files next to a post and refer to them like any other image. The published files are the same WebP variants and JPEG viewer image as for a JPEG, and the original is not published:

sharp’s prebuilt binaries cannot read HEIC, so coffer detects the format by the first bytes of the file (an ftyp box with a HEVC brand such as heic, whatever the file is called) and decodes it with heic-decode, which is libheif compiled to WebAssembly. The raw pixels are then handed to sharp. Nothing has to be installed on your machine.
- Orientation. The rotation and mirroring that a phone stores in the file (the
irotandimirproperties) are applied by the decoder, so the published files are upright. When a file has neither property but an Exif orientation, exifr reads it and coffer turns the pixels accordingly. When the file has such a property the Exif orientation is ignored, as the HEIF standard says, so a picture is never turned twice. - Metadata. As for every image, the position and the camera fields are read from the Exif item (with exifr) and published only as the metadata policy allows; see What the files carry.
- Errors. A HEIC file that cannot be decoded (damaged, cut short, or using a HEIF feature that libheif-js lacks) fails the build. The message names the file and says what to do, for example
image 'IMG_4021.HEIC': cannot decode the HEIC image "IMG_4021.HEIC": Could not parse HEIF file ...; convert the file to JPEG or PNG (for example by exporting it from your photo app) and use that instead. A file called.heicthat is not HEIC at all fails the same way. As with other formats, a damagedcoveris a warning, and the post gets a generated card instead. - Limits.
- Only the first (primary) picture of a file is used: no burst sequences, Live Photo videos, depth maps or HDR gain maps.
- Pictures are decoded to 8 bits per channel and the colour profile is not converted: a Display P3 photo is treated as sRGB, so very saturated colours look slightly duller than on the phone.
- The whole decoded picture is held in memory (4 bytes per pixel while decoding, 3 afterwards), so a 48 megapixel photo needs a few hundred megabytes while it is processed. It counts as one of the images processed at the same time, see The cache.
- Decoding in WebAssembly is noticeably slower than sharp’s own decoders. The result is cached like any other, so that cost is paid once per photo.
- libheif prints a line to the console for a file it cannot parse, in addition to the build error.
- AVIF, which is also a HEIF file, is not supported.
- libheif is licensed under the LGPL-3.0, heic-decode under the ISC license and exifr under the MIT license.
What the Build Makes
For every image, in the img/{key}/ folder of the site’s output (the {key} is a hash of the original and of the settings, so a changed photo gets a new address and old addresses can be cached for ever):
| File | What |
|---|---|
{name}-{width}.webp |
A WebP variant, one for each configured width that is narrower than the original. When the original is not wider than the widest configured width, its own width is a variant too, so the full picture is always offered and nothing is ever enlarged. |
{name}-full.jpg |
One JPEG for the viewer: the full picture, its long edge capped at viewerMaxEdge. |
{name} comes from the file name of the original, in lower case with anything but letters and digits turned into hyphens. The original is never copied to the output.
- The EXIF orientation is applied: a photo that a phone stored sideways with orientation 6 is published upright, and the size recorded for it (and written into the page) is the upright size.
- The WebP variants never carry metadata: no EXIF, no GPS position, no camera fields, no colour profile (pixels are converted to sRGB first). The viewer JPEG carries only what the metadata policy allows, see below.
- Transparency in a PNG is kept in the WebP variants; the viewer JPEG has a white background.
The default widths are 480, 800, 1200, 1600 and 2400 pixels and the viewer image is capped at 3200 pixels; see images to change them. An original of 3000 by 2000 pixels gets variants at 480, 800, 1200, 1600 and 2400 and a viewer JPEG at 3000 by 2000; one of 700 by 500 gets 480 and 700 and a viewer JPEG at 700 by 500.
Full-Resolution Downloads
A picture that people are meant to download at its full size, such as a screenshot in the press kit of a game, does not use the viewer JPEG, whose size is capped. pipeline.download(file, policy) makes a file of the pixel size of the upright original instead, and publishDownload(download, outDir, address) copies it to an address the caller chose from checked text. The picture is turned upright, re-encoded and never reduced, so the metadata policy applies to it exactly as it does to the viewer JPEG (strip, coarse or keep for the position, strip or keep for the camera; nothing else is ever copied):
| Original | Download |
|---|---|
| PNG | PNG, with its transparency |
| WebP with transparency | PNG |
| JPEG, HEIC, opaque WebP | JPEG at quality 95 (the pipeline option downloadJpegQuality, not a site setting; 4:4:4), on a white background where there was transparency |
Downloads are kept in the cache beside the other images (dl-{key}/, keyed by the hash of the original, the policy and the quality), so an unchanged file is made once.
What the Files Carry
Before an image is processed, coffer decides its policy (see Location and camera metadata): a location of strip, coarse or keep, and a camera of strip or keep. The WebP variants always carry nothing. The full-size viewer JPEG carries:
| Policy | What the viewer JPEG has |
|---|---|
location: strip |
No position. |
location: coarse |
The position rounded to two decimals of a degree, about a kilometre (for example 47.0123, 11.0456 becomes 47.01, 11.05). |
location: keep |
The exact position. |
camera: strip |
No camera fields. |
camera: keep |
Make, model, lens make and model, exposure time, f-number, ISO and focal length (also on a 35 mm scale), for the fields the original has. |
Only these fields are ever copied, and only as the policy says. The time the picture was taken, the altitude, serial numbers, the name of the owner, thumbnails, maker notes, XMP and IPTC data are never published. The orientation is applied to the pixels and is not written, so the file needs no turning.
The position is read from the Exif of the original with exifr and written as the Exif GPS fields with sharp, so any program that reads Exif (including exifr) reads back what the policy allows. A picture that has no position, or whose format exifr cannot read a position from (a WebP or PNG original, for example), publishes none whatever the policy says. The policy is part of the cache key, so the same photo used in two posts with different policies is published twice, in two folders, and a change of policy gives the files new addresses.
coffer check reads every published image back and fails if what it finds does not match the policy recorded in the manifest, see Checking a finished build.
What the Page Looks Like
<figure>
<picture>
<source type="image/webp"
srcset="/img/3223a574853e9d3b/dovetail-joint-480.webp 480w, /img/3223a574853e9d3b/dovetail-joint-800.webp 800w, /img/3223a574853e9d3b/dovetail-joint-1200.webp 1200w"
sizes="(min-width: 44rem) 41rem, calc(100vw - 2rem)">
<img src="/img/3223a574853e9d3b/dovetail-joint-1200.webp" alt="Two boards joined by three dovetails."
width="1200" height="800" loading="lazy" decoding="async">
</picture>
<figcaption>The sixth attempt, unglued, on the bench.</figcaption>
</figure>
- Every
<img>haswidthandheight, so the browser reserves the space before the file arrives and the page does not jump. The stylesheet scales it (max-width: 100%; height: auto). - The
srcis the variant closest to 1200 pixels without exceeding it (else the narrowest), for readers that ignoresrcset. - All images of a page but the first have
loading="lazy"anddecoding="async". The first image, which is likely to be on screen when the page opens, loads at once. “First” means the first<img>of the page’s Markdown, whether or not coffer could process it. - An image inside a sentence, or inside a link, is a
<picture>without a<figure>, and a title is kept as a tooltip. - Several images on lines of their own in one paragraph become one figure each.
- Every image is a link to its full-size JPEG and opens in a fullscreen viewer when scripts are on: see The image viewer.
- Images can also be shown one at a time in a row that scrolls sideways: see Carousels. Slides are lazy like any other image: only the first image of the page, which is the first slide when a page starts with a carousel, loads at once.
- The
sizesattribute says how wide the image is shown. The default fits the text column of the default theme; a theme with another layout setsimages.sizes.
Feeds
Feed readers rarely understand <picture>, so in a feed every picture is a plain <img> with the 1200 pixel variant as an absolute address, with its width and height and without srcset, loading and decoding. See Feeds.
The Cache
Processing a large photo takes a moment, so results are kept in .cache/images/ beside the configuration file (or in the cacheDir option of buildSites, see Building a site). The folder name is a hash of the original’s content, its name, the settings and the versions of the image libraries; a photo whose bytes and settings are unchanged is not processed again, so the second build of a site is much faster than the first. Deleting .cache/ is always safe: the next build makes everything again. A cache folder that is incomplete is made again.
Images are processed at the same time, a few at once (at most four or the number of CPU cores, whichever is lower), so a post with a hundred photos does not exhaust the memory of the machine.
The Manifest
Each image a page uses is listed in .coffer-manifest.json under images, so checks can compare what was published with what was intended:
{
"source": "content/journal/first-dovetail/dovetail-joint.jpg",
"post": "/journal/first-dovetail/",
"use": "body",
"sha256": "...",
"width": 1200,
"height": 800,
"outputs": [
{ "role": "variant", "url": "/img/3223a574853e9d3b/dovetail-joint-480.webp", "file": "img/3223a574853e9d3b/dovetail-joint-480.webp", "type": "image/webp", "width": 480, "height": 320 },
{ "role": "viewer", "url": "/img/3223a574853e9d3b/dovetail-joint-full.jpg", "file": "img/3223a574853e9d3b/dovetail-joint-full.jpg", "type": "image/jpeg", "width": 1200, "height": 800 }
]
}
source is relative to the configuration file, post is the address of the page that uses the image (/ for the home page) and use is body for a Markdown image and cover for a post’s cover. width and height are the upright size of the original. An image used by two pages has two entries.
Each entry also says what was published of the image’s metadata, so that maps and checks need not open the files:
{
"policy": {
"location": { "value": "keep", "source": { "level": "tag", "origin": "trips/mountains" } },
"camera": { "value": "keep", "source": { "level": "tag", "origin": "trips/mountains" } }
},
"gps": { "latitude": 47.012305, "longitude": 11.045611, "precision": "exact" },
"camera": { "make": "Examplecam", "model": "Made-up 1" }
}
policyis the effective policy and where each setting came from (levelissite,tag,postorimage;originis the tag path, the post file relative to the configuration file, or the key in theimagesmap).gpsis the position the viewer JPEG carries:"precision": "exact", or"coarse"with the rounded coordinates, ornull. It is never more precise than the policy allows, so a map may show it.cameralists the camera fields the viewer JPEG carries, or isnull.
The Example Photos
The example site’s photographs are made up and generated, so nothing copyrighted ships with coffer. example/scripts/make-photos.js draws them with sharp and writes small JPEGs below example/content/; they are committed, so you only run the script (node example/scripts/make-photos.js in the coffer directory) to change them. One of them, journal/photos/ridge.jpg, is stored sideways with EXIF orientation 6 and carries a made-up GPS position and camera, to show what the pipeline does with a phone photo: its tag trips/mountains says location: keep and camera: keep, so its viewer JPEG carries both. journal/first-dovetail/dovetail-joint.jpg has a made-up position too, and its post says location: coarse, so only the rounded position is published.
The post journal/photo-notes of the example site shows its three photos in a carousel (and again as a list). It reuses the photos of the other posts, which are therefore published once more under the settings of that post.
From JavaScript
import { createImagePipeline } from 'coffer';
const pipeline = createImagePipeline({ cacheDir: '.cache/images', widths: [480, 960] });
const image = await pipeline.process('/abs/path/photo.jpg', { location: 'coarse', camera: 'strip' }); // throws ImageError for a bad file
pipeline.publish(image, 'dist/site'); // copies variants and viewer image to dist/site/img/{key}/
process takes the metadata policy as its second argument (both settings default to strip) and returns the upright width and height, the variants and the viewer file (each with file, width, height and bytes), the policy, the published gps ({ latitude, longitude, precision } or null) and camera fields, the cache folder dir, the published folder url and whether the files were cached. pipeline.stats counts images generated and reused.
The third argument names the files: process(source, policy, { name: 'youtube-preview' }). The name replaces the one derived from the file, so the files are {name}-{width}.webp and {name}-full.jpg. It must match ^[a-z0-9]+(?:-[a-z0-9]+)*$ (lower-case letters and digits separated by single hyphens) and be at most 60 characters; anything else throws a TypeError. A given name is part of the cache key, so the same file processed with and without a name gives two results.