Skip to content
GigadriveDocs

Images

The images block declares which sources may be optimized, which sizes and formats are allowed, and any named variants.

An images block is the policy the edge enforces when it resizes and re-encodes an image. It is a whitelist first and a set of defaults second: a request asking for a width or a source host the policy does not list is rejected rather than served.

Declaring a policy

version: 4

images:
  remotePatterns:
    - protocol: https
      hostname: cdn.example.com
      pathname: /images/**
  widths: [640, 1080, 1920]
  qualities: [60, 80]
  formats: [image/avif, image/webp]
  minimumCacheTTL: 86400
  variants:
    thumb:
      width: 320
      height: 320
      fit: cover
      format: image/webp

Every sub-key is optional. Whether the block is there at all is not: omitting images emits no policy, and writing it fills in every key you leave out from the defaults in the following table. The keys are strict, so a typo such as qualitys fails the build with a validation error rather than being ignored.

Keys

KeyTypeAcceptedDefault
widthslist of integers1 to 64 unique values, each 1 to 8192[640, 750, 828, 1080, 1200, 1920, 2048, 3840]
heightslist of integersup to 64 unique values, each 1 to 8192[]
qualitieslist of integers1 to 100 unique values, each 1 to 100[75]
formatslist of media types1 to 4 of image/avif, image/webp, image/jpeg, image/png[image/avif, image/webp]
localPatternslist of objectsup to 64 entries[{ pathname: /** }]
remotePatternslist of objectsup to 64 entries[]
minimumCacheTTLinteger, seconds0 to 3153600014400
dangerouslyAllowSVGbooleanfalse
contentSecurityPolicystring4096 characters at mostdefault-src 'self'; script-src 'none'; sandbox;
contentDispositionTypestringinline or attachmentattachment
maximumRedirectsinteger0 to 103
maximumResponseBodyinteger, bytes1024 to 10485760052428800
variantsmapup to 100 named entries{}

A width or quality that is not in its list is refused, which is what keeps an open image endpoint from becoming an unbounded transform farm. dangerouslyAllowSVG carries its name for a reason: SVG is executable markup, and the contentSecurityPolicy and contentDispositionType defaults are what contain it when you turn it on.

Which sources may be optimized

localPatterns govern paths inside your own deployment, and each entry takes a pathname glob and an optional search string. remotePatterns govern everything else. An entry needs a hostname and may add protocol (http or https), port, pathname, and search. A remote host that matches no entry is refused before any fetch happens, so an empty remotePatterns list means local sources only.

Variants

A variant is a named bundle of transform parameters, asked for with a variant query parameter instead of spelling out the size and format on every request. A name is up to 64 characters of letters, digits, underscores and hyphens, starting with a letter or digit, and each variant sets at least one of width, height, quality, format, and fit. fit is one of contain, cover, fill, inside, or outside.

Parameters on the request win over the variant's values, so asking for thumb with a quality of 60 keeps that variant's dimensions and overrides its quality. A name no variant matches returns 400. Image optimization covers the request URL itself.