Edgeweir
Sites

Image format conversion

Image format conversion on a site's Cache tab: nodes convert cached JPEG and PNG to WebP or AVIF by Accept, cache variants, and fall back to the original.

Concepts

TermDefinition
VariantThe three cached objects of one URL: the original, WebP and AVIF. The cache key tells only these three apart; it does not contain the visitor's Accept.
NegotiationThe node picks the class from Accept: AVIF when image/avif is named explicitly (q > 0) and the site offers AVIF, otherwise WebP when image/webp is named explicitly (q > 0) and the site offers WebP, otherwise the original.
Source typesThe originals converted: image/jpeg, image/png.
Saved bytesFor every complete 200 GET response served as a variant (cache hits included), the bytes it has less than the original, summed.

Conversion keeps the size, does not crop, and reads no URL parameters.

Turning it on

  1. Open Sites, select the site, and open the Cache view.
  2. Make sure a Cache rules entry caches the paths of the images: only cached requests are converted (the card notes "Converts cached images only").
  3. In the Image format conversion card, turn on On; in the WebP and AVIF groups turn on the formats to offer and set their Quality; under Source types choose JPEG and/or PNG; change Smallest original (bytes), Largest original (bytes), and Most pixels under Limits as needed.
  4. Click Save.
  5. Verify: see Verifying; the Saved by conversion card shows the bytes saved over the chosen range.

Settings

FieldAPI fieldValuesDefaultEffect
OnenabledOn / offOffTurning it off keeps the other settings
WebP: OnwebpOn / offOnOffers WebP; at least one of WebP and AVIF
WebP: QualitywebpQualityWhole number 1–10080Lossy encoder quality
AVIF: OnavifOn / offOffOffers AVIF; smaller files, but a conversion needs about 3–4 times the memory of WebP
AVIF: QualityavifQualityWhole number 1–10050Lossy encoder quality
Source types: JPEGjpegOn / offOnConverts image/jpeg; at least one of JPEG and PNG
Source types: PNGpngOn / offOnConverts image/png, also lossily; turn it off when icons or screenshots must stay lossless
Limits: Smallest original (bytes)minSize0–671088641024Smaller originals are not converted; not above the largest
Limits: Largest original (bytes)maxSize1–6710886410485760Larger originals are not converted
Limits: Most pixelsmaxPixels1–5000000016000000Images whose width × height is larger are not converted
ItemBehavior
ValidationThe settings are checked as a whole, also while off. Both formats off shows "Choose at least one format", both source types off "Choose at least one source type", the smallest original above the largest "The smallest original cannot be larger than the largest"
ApplyingA save publishes a revision of the site's cluster (reason site_updated, audit site.image_convert_update with the names of the changed fields and enabled); nodes apply it as a hot update without reloading nginx. Changes while conversion is off do not change the node configuration and create no revision
Node requirementNode capability image-convert-v1; while an active node of the cluster lacks it, the card shows "Some nodes in the cluster do not support it", On is unavailable while off, and a conversion that is on can still be turned off. A node running with --image-workers 0 refuses configurations that turn conversion on

Saved by conversion

The Saved by conversion card shows the bytes saved over the chosen range.

ItemMeaning
RangeLast hour, Last 6 hours, Last 24 hours (default), Last 7 days, Last 30 days
CountingComplete 200 GET responses only; HEAD and 206 do not count
PartialWhile an active node of the cluster lacks image-convert-v1, the card shows "Some nodes in the cluster do not convert images"

Behavior

CaseResult
The request is not cached (no cache rule applies, bypassed, Authorization without a rule that caches it, not GET / HEAD, WebSocket, gRPC)No conversion; the response is as if it were off
Accept names text/html (q > 0: a browser navigation, e.g. opening the image in a new tab)The original
The path's last segment has an extension other than the source types' (JPEG: .jpg .jpeg .jpe .jfif; PNG: .png; any case)No variants, no Vary: Accept
A path without an extensionNegotiated as usual; the origin's Content-Type decides whether it is converted
Accept has only */* or image/* (curl's default, for example)The original
An eligible request answered with image/jpeg, image/png, image/webp, image/avifVary: Accept (the original's too)
A variant's cache missThe node fetches the whole original from the origin (no slices), converts and caches it; later requests for that variant hit
A variant responseContent-Type: image/webp / image/avif; ETag with -webp / -avif inside the quotes; cached as long as the original; no metadata (EXIF, XMP, ICC)
The original has an EXIF orientationThe pixels are turned upright before encoding; it looks like the original
The origin answers other than 200, with a Content-Encoding, another type than the source types, or out of the size or pixel rangeThe original, cached under that variant as usual
An ICC profile that is not sRGB (e.g. Display P3) or over 64 KiB, CMYK JPEG, a PNG whose gAMA is not 1/2.2 without an sRGB chunk, a PNG with more than one iCCP chunk or with both iCCP and sRGB, animated PNG, arithmetic-coded or 12-bit JPEGThe original, cached as usual
The variant is not smaller, the conversion fails or times outThe original, cached as usual
The node is busy (conversion slots or memory taken, after waiting 1 second)The original, cached for at most 60 seconds, then tried again
The original has not arrived within --image-timeoutThe original (streamed on), cached for at most 60 seconds, then tried again
Purging a URL, directory or Cache-TagEvery variant of the URL is purged with it
HEAD, RangeAnswered from the cached variant

Limits on the node

Conversions run in child processes of the node's agent, one CPU each. These are node flags (also EDGEWEIR_<NAME> environment variables, such as EDGEWEIR_IMAGE_WORKERS); restart edgeweir-node after changing them:

FlagDefaultNotes
--image-workersmin(4, max(1, CPUs / 2))Concurrent conversions; 0 turns conversion off and the node does not announce image-convert-v1
--image-memory-mb1024Memory the running conversions may use together. Each conversion is estimated from its pixels (WebP about 48 bytes per pixel + 32 MiB, AVIF about 160 bytes per pixel + 64 MiB); images whose estimate exceeds the total are not converted. Originals held in the agent's memory before their conversion count against the same total
--image-timeout8sLongest conversion; the original is served after it

With the defaults, AVIF converts images up to about 6 megapixels and WebP up to about 20; larger images reach AVIF clients as the original.

Verifying

# MISS the first time, HIT the second, type image/webp
curl -s -o /dev/null -D - -H 'Accept: image/webp,*/*' https://img.example.com/photo.jpg | grep -iE '^(x-cache|content-type|vary):'
# AVIF
curl -s -o /dev/null -D - -H 'Accept: image/avif,image/webp,*/*' https://img.example.com/photo.jpg | grep -iE '^(x-cache|content-type):'
# The original
curl -s -o /dev/null -D - https://img.example.com/photo.jpg | grep -iE '^(x-cache|content-type|vary):'

The node logs one image converted line per conversion (original and variant bytes, pixels, time and CPU time); timeouts and failures log image conversion timed out / image conversion failed.

API

Paths are relative to /api/v1, see API and endpoints.

ProcedureMethod and pathNotes
imageConvert.getGET /sites/{id}/image-convertThe site's settings; the defaults (off) when never saved
imageConvert.updatePUT /sites/{id}/image-convertReplaces the settings as a whole, every field of Settings required; publishes the cluster
imageConvert.savingsGET /sites/{id}/image-convert/savingsrange: 1h, 6h, 24h (default), 7d, 30d; returns bytesSaved and unsupportedNodes (active nodes without image-convert-v1)
sites.featuresGET /sites/{id}/featuresimageConvert tells whether the cluster can turn conversion on

Settings that fail the validation answer 400. Service accounts cannot call these procedures. Copying settings and cloning a site copy the image format conversion settings too, see Site management.

Limits

ItemDescription
FormatsOnly JPEG and PNG are converted; GIF, SVG, WebP and AVIF are served as they are
TransformationsNo resizing, cropping, watermarks or transformations by URL parameters
Cache spaceEach variant takes its own cache space; at most three objects per URL

Troubleshooting

SymptomCauseAction
Always the original, X-Cache: BYPASSNo cache rule caches the requestAdd a cache rule for the image paths, see Configure cache rules
Always the original, without Vary: AcceptThe path's extension is not one of the chosen source types'Choose the matching source type, or use extensions such as .jpg and .png
Always the original, with Vary: AcceptAccept names neither image/webp nor image/avif explicitly, or names text/html; the image is out of the size or pixel range, not sRGB, or the variant is not smaller; the conversion failed or timed outCheck with the requests under Verifying; look for image conversion failed / image conversion timed out in the node log
On is unavailable with "Some nodes in the cluster do not support it"An active node of the cluster lacks image-convert-v1, or runs with --image-workers 0Upgrade the nodes, see Node upgrades; drop --image-workers 0
Saving shows "Choose at least one format", "Choose at least one source type", or "The smallest original cannot be larger than the largest"The settings fail validationChange them as the message says
A node stays on an old configuration revisionIt runs with --image-workers 0 and refuses configurations that turn conversion onChange that node's --image-workers and restart it, or turn conversion off
High node memoryToo many concurrent conversions or too many pixelsLower --image-workers or --image-memory-mb, or lower Most pixels or turn AVIF off on the site
Edit on GitHub

On this page