Skip to content

@ogygia/image

Options

Every option of the image() plugin, every preset key, every option a source takes in import.meta.og.image(), the formats and qualities files are made at, the pixel operations, and every message code the package can print.

On this page

This page is the reference. Options live in three places: the plugin’s (image({ … }) in vite.config.ts, defaults for every image), a preset’s (how a page shows an image), and a source’s own (the macro’s second argument, which belongs to the file whatever page shows it). Every key is checked at build: an unknown key fails with image_option_unknown and a bad value with image_option_invalid, each naming the key, so a typo never goes unnoticed. The one exception is ops: its values go to sharp unchecked (below).

import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { image } from '@ogygia/image/vite';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    ogygia(),
    image({
      presets: { thumb: { width: 400, aspect: '1/1' } },
      formats: ['avif', 'webp'],
      quality: 70,
      breakpoints: [320, 640, 1280, 2048]
    }),
    sveltekit()
  ]
});

Plugin options

OptionDefaultWhat it does
presets{}Named ways to show an image (Presets).
quality60 for AVIF, 80 for WebP and JPEGEncoder quality for every file, a whole number from 1 to 100. A PNG is lossless unless a quality is set.
formats['avif', 'webp']The formats to offer, best first: 'avif', 'webp', 'png', 'jpeg'. The last is the <img>’s fallback. A moving image is animated WebP whatever this says.
placeholdertrueMake the blur placeholder for every source.
breakpoints[320, 480, 640, 960, 1280, 1600, 2048]The width ladder a responsive image is offered at, capped at the image’s own width (Pick a layout).
markdown{}Markdown images: { width } is the prose column’s width when there’s no prose preset, { animated } names a moving image’s preset, false turns them off (Images in markdown).
encodersharp()Who makes live files: sharp(), cloudflare(), vercel(), or a list in order of priority (Deployment).
themenone{ dark, light }: the CSS selectors an app’s theme switch writes, which a dark file then follows (Follow your app’s theme switch).
remotenoneImages on other hosts: { hosts, maxBytes?, timeout?, maxAge? } (Images from other hosts).

Presets

A preset takes these keys. Each prop an <Img> passes says over the preset’s value. A preset name starts with a letter and holds letters, digits, - and _.

KeyWhat it is
layout'constrained' (the default), 'fullWidth' or 'fixed'.
widthDisplay width, in CSS pixels. A whole number above 0. Doesn’t set the size with fullWidth.
heightDisplay height. With width, the box the files are cropped to.
aspectThe box’s shape, 16 / 9 or '16/9' ('16:9' works too).
positionWhere a crop keeps: 'center', 'centre', 'top', 'bottom', 'left', 'right', 'attention', 'entropy'.
sizesReplaces the sizes the layout works out.
priorityThe page’s main image: eager, high priority, preloaded.
placeholderPaint the blur placeholder. Default true.
morphName the image for a view transition by its source.
qualityEncoder quality, 1 to 100, for the files this preset asks for.
formatsThe formats to offer, best first. A non-empty list.
artArt twins: [{ media, aspect?, position?, width? }] (Art direction).
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { image } from '@ogygia/image/vite';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    ogygia(),
    image({
      presets: {
        cover: {
          layout: 'fullWidth',
          aspect: '16/9',
          priority: true
        },
        share: {
          width: 1200,
          height: 630,
          formats: ['jpeg'],
          quality: 85
        },
        diagram: {
          width: 720,
          formats: ['png'],
          placeholder: false
        }
      }
    }),
    sveltekit()
  ]
});

Source options

The macro’s second argument belongs to the file, whatever page shows it. import.meta.og.image.glob() takes the same options, except dark and art.

OptionDefaultWhat it does
qualitypluginEncoder quality, 1 to 100, for every file made from this source. A preset’s or getImage()’s says over it.
placeholderpluginMake the blur placeholder. false makes none.
opsnonePixel operations: turns, mirrors, filters and color changes (below).
warmnoneA preset name, or a list: make those presets’ files at build (warm).
darknoneThe dark file, a path of the same shape (Show a dark version).
artnoneOther files by media condition, { '(max-width: 600px)': './x.jpg' } (Art direction).

Pixel operations

ops takes sharp’s operations of the same names: rotate (degrees), flip and flop (mirror vertically and horizontally), grayscale, blur (a sigma), sharpen, normalize, negate, gamma, tint (a color) and modulate ({ brightness, saturation, hue, lightness }). A quarter rotate swaps the image’s width and height.

sharp applies them in its own order, not the order you write them. flip and flop come first, then rotate, then the resize or crop. The filters and color changes (blur, sharpen, normalize, tint, modulate and the like) run on the resized file’s pixels, so a blur sigma is measured in the file’s pixels and normalize stretches each file’s own range. gamma is applied around the resize. Cloudflare follows the same order.

Crops aren’t an op: they belong to how a page shows the image (aspect, position). The operations ride in each file’s name, so a source with ops has files of its own. Cloudflare can make only some operations and Vercel none (What each encoder can make).

The keys are checked at build; the values go to sharp as they are. A value sharp refuses (blur: 0.1, gamma: 5, a tint that isn’t a color) fails the build as image_decode_failed. With placeholder: false, the build may not open the file, so the error moves: a prerendered page or a warmed preset fails the build (image_unsettled), and a file made on request at the image endpoint answers 500. Cloudflare’s links handle ops their own way: they clamp blur into Cloudflare’s range and refuse gamma and tint (image_encoder_cannot). Stick to what sharp takes: blur 0.3 to 1000, gamma 1 to 3. sharp turns by any angle, but use quarter turns: any other rotate gives the descriptor its unrotated size (#2290).

export const team = import.meta.og.image('./images/team.jpg', {
  quality: 70,
  placeholder: false,
  ops: { grayscale: true },
  warm: ['cover', 'thumb']
});
export const scan = import.meta.og.image('./images/scan.jpg', {
  ops: {
    rotate: 90,
    normalize: true,
    modulate: { saturation: 0.8 }
  }
});

Formats and quality

By default each image is offered as AVIF at quality 60 and WebP at quality 80, best first, and the <img>’s fallback is WebP. JPEG is made at 80 with mozjpeg, and PNG losslessly at the highest compression unless a quality is set. sharp makes AVIF at effort 2 of 0 to 9; sharp({ effort: { avif } }) changes it (sharp()).

A quality set in more than one place is picked in this order: getImage()’s or the preset’s, then the source’s, then the plugin’s, then the format’s default.

Some files are special:

  • An animated GIF or WebP, or any source with more than one frame (a multi-page TIFF counts, #2290), is offered as animated WebP only, whatever formats says, with a first-frame still for visitors who ask for less motion (Less motion). Every frame is kept: a 1200 × 800 screen recording of 300 frames encodes in about half a second.
  • An SVG is served as it is, with no srcset and no placeholder: it already scales.
  • A transparent image gets no blur placeholder, since the blur would show through.
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { image } from '@ogygia/image/vite';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    ogygia(),
    image({ formats: ['avif', 'webp', 'jpeg'], quality: 75 }),
    sveltekit()
  ]
});

Limits

LimitValueWhat happens past it
Pixels in one frame of a source268,402,689 (16383 × 16383)image_too_large at build
Pixels over all the frames of an animation4,294,967,296image_too_large at build
A file’s width or height99999 pixelsimage_prop_invalid at render
A share card’s props in a URL2048 charactersimage_card_props
A remote image’s sizeremote.maxBytes, 20 MBrefused (413 on request, image_remote_failed at build)
A remote fetch’s timeremote.timeout, 10 srefused (504 on request)
Redirects one remote fetch follows3refused
Encodes waiting on a live server64, each for 30 s503 with image_busy
The build cache’s files2 GBthe least recently used go
A live server’s files on disk512 MBthe least recently used go
Files kept in memory when the disk fails64 MBthe least recently used go

Entry points and types

ImportWhat it holds
@ogygia/imageImg, getImage, isImage, remoteImage; types ImageDescriptor, ImageFormat, ImageOps, Twin, ImageLayout, ImagePosition, ImagePreset, OutputFormat, Laid, LaidSource, LaidPreload, LayoutRequest, GetImageOptions, RemoteImageOptions.
@ogygia/image/Img.svelteThe <Img> component alone.
@ogygia/image/viteimage, sharp, cloudflare, vercel; types ImagePluginOptions, ImageOptions, ImageRemote, ImageTheme, Encoder, SharpOptions, CloudflareOptions, VercelOptions, VercelImages, VercelRemotePattern, and again ImageLayout, ImageOps, ImagePosition, ImagePreset, OutputFormat.
@ogygia/image/typesThe types of import.meta.og.image, .glob() and .card(), for src/ogygia.d.ts.

Descriptors

An ImageDescriptor is plain data: it crosses island props, sits in frontmatter and in a load’s result, and is written into a module as a literal. It names no encoded file; <Img> picks those at render. Make descriptors with the macro, remoteImage() or a card maker, not by hand: the render checks the id and the placeholder, and a live server checks that the id matches the file src names.

FieldWhat it is
idThe source’s identity: a hash of its bytes. For a remoteImage(), r and a hash of its URL and version; for a card, c and a hash.
srcThe original file’s URL, shipped as an asset. A remoteImage()’s URL; a card’s own-size PNG.
widthThe image’s width in pixels, after its EXIF orientation and ops.
heightThe image’s height in pixels, the same way.
formatThe source’s own format: 'avif', 'webp', 'png', 'jpeg', 'gif', 'svg' or 'tiff'.
phThe placeholder, a 16-pixel-wide WebP data: URL. Absent for a transparent image, an SVG, a remoteImage(), a card, or placeholder: false.
animatedtrue for a source the build read with more than one frame: an animated GIF or WebP, or a multi-page TIFF. Absent otherwise, a remoteImage() included.
qualityThe source’s own quality, when the macro set one.
opsThe source’s pixel operations, when it has any.
warmThe presets the build made this source’s files for.
altAlt text the source carries: remoteImage()’s alt. A markdown image passes its text to <Img alt> instead.
from'remote' for a remoteImage(), 'card' for a share card. Absent for a file the build read.
cardA card’s component and props, as its file URLs carry them.
twinsThe source’s own twins: its dark file and its art files, each a Twin with its own descriptor.

Message codes

Every message the package prints is a code with a page of its own. Errors stop the build or the render; warnings are printed once and the work goes on.

At build

CodeWhen
image_no_kitsveltekit() isn’t in the plugin list.
image_sharp_missingsharp isn’t installed and listed, or a server build has it only in devDependencies.
image_option_unknownAn option key the plugin, a preset, a source or an encoder doesn’t take.
image_option_invalidAn option with a value that can’t be used, a bad encoder list, or an encoder on the wrong adapter.
image_macro_arityThe macro got no argument, or more than two.
image_macro_not_literalA path or options the build can’t read before the code runs.
image_query_invalidAn ?og-image import written by hand.
image_not_foundA path that names no file.
image_outside_srcAn image outside src/, or under src/lib/server/ or a test file.
image_glob_emptyA glob that matched no file.
image_decode_failedA file sharp can’t decode.
image_too_largeA frame, or an animation, past the pixel limits.
image_warm_unknownwarm names a preset the config doesn’t declare.
image_markdown_htmlAn HTML <img> in markdown that names a local file.
image_markdown_no_fileA local image in markdown rendered from a string.
image_path_malformedA markdown image path whose escapes aren’t UTF-8.
image_remote_hostA remote URL, or a redirect, on a host remote.hosts doesn’t list.
image_remote_failedA remote image the build couldn’t fetch and has no copy of.
image_card_engine_missingA card, and satori, satori-html or resvg isn’t installed (or not in dependencies).
image_card_fontA card font that’s missing, WOFF2, unreadable, or no font at all.
image_card_cssCSS satori can’t draw (also on request).
image_card_sourceAn image a card names that it can’t draw (also on request).
image_unsettledA file a prerendered page or a warmed preset names that the build couldn’t make.
image_mark_leftA prerendered image URL changed so the build can’t find it, or made absolute at Kit’s default origin.
image_vercel_configadapter-vercel’s images lacks or opens too much, or vercel() on another adapter.
image_still_left_outWarning: the encoders can’t make a moving image’s still.
image_remote_staleWarning: a remote image couldn’t be asked again, so the build used its copy.

At render and on request

CodeWhen
image_preset_unknown<Img preset> or getImage() names a preset the config doesn’t declare.
image_prop_invalidA size, aspect, position, quality or twin no file can have, or a hand-changed descriptor.
image_remote_invalidremoteImage() got a bad URL, size, alt or version.
image_encoder_cannotA page rendered on request asks the encoder for a crop, operation or format it can’t make.
image_no_server<Img> rendered on a server without ogygia’s handle, or a card made in the browser.
image_card_propsA card’s props aren’t JSON, or are too long.
image_watch_rebuildA vite build --watch rebuild’s page names a file no build made.
image_settle_failedWarning: the endpoint couldn’t make a file and answered 500.
image_source_changedWarning: a file asked for an original that has changed since the page rendered; 404.
image_no_encoderWarning: this server can’t make files (no sharp) or draw cards; also once at build on an edge adapter.
image_binding_missingWarning: the Worker has no Images binding of that name.
image_busyWarning: too many files waiting; asks answer 503.
image_remote_refusedWarning: a remote image was refused (404, 413, 502, 504).
image_store_write_failedWarning: the file store couldn’t write; files are kept in memory.
image_store_unsafeWarning: the store’s folder isn’t this user’s alone; nothing is kept.
image_share_formatWarning, in dev: an og:image or twitter:image names an AVIF or WebP file.

Build bookkeeping

A build notes the images its prerendered pages name in a run folder of its own, under node_modules/.ogygia/image/runs/ (or ogygia-image-<uid>/runs/ in the system’s temporary folder with no cache), and hands it to the processes it starts in the environment variable __OGYGIA_IMAGE_BUILD. These warnings are about that folder and about vite build --watch. Most mean a variable was left over from another build: unset __OGYGIA_IMAGE_BUILD before you build.

CodeWhen
image_run_refusedThe build was handed a notes file outside a runs folder it owns, and went on without it.
image_run_keptThe build couldn’t delete its run folder. A later build removes it a day later.
image_folder_refusedThe build was handed a store or remote folder it doesn’t own, and used its own.
image_owed_endUnder --watch on SvelteKit 3, a rebuild started before the last build’s images were all made.
image_pages_leftUnder --watch, pages whose images failed couldn’t all be removed from the output.