@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
| Option | Default | What it does |
|---|---|---|
presets | {} | Named ways to show an image (Presets). |
quality | 60 for AVIF, 80 for WebP and JPEG | Encoder 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. |
placeholder | true | Make 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). |
encoder | sharp() | Who makes live files: sharp(), cloudflare(), vercel(), or a list in order of priority (Deployment). |
theme | none | { dark, light }: the CSS selectors an app’s theme switch writes, which a dark file then follows (Follow your app’s theme switch). |
remote | none | Images 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 _.
| Key | What it is |
|---|---|
layout | 'constrained' (the default), 'fullWidth' or 'fixed'. |
width | Display width, in CSS pixels. A whole number above 0. Doesn’t set the size with fullWidth. |
height | Display height. With width, the box the files are cropped to. |
aspect | The box’s shape, 16 / 9 or '16/9' ('16:9' works too). |
position | Where a crop keeps: 'center', 'centre', 'top', 'bottom', 'left', 'right', 'attention', 'entropy'. |
sizes | Replaces the sizes the layout works out. |
priority | The page’s main image: eager, high priority, preloaded. |
placeholder | Paint the blur placeholder. Default true. |
morph | Name the image for a view transition by its source. |
quality | Encoder quality, 1 to 100, for the files this preset asks for. |
formats | The formats to offer, best first. A non-empty list. |
art | Art 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.
| Option | Default | What it does |
|---|---|---|
quality | plugin | Encoder quality, 1 to 100, for every file made from this source. A preset’s or getImage()’s says over it. |
placeholder | plugin | Make the blur placeholder. false makes none. |
ops | none | Pixel operations: turns, mirrors, filters and color changes (below). |
warm | none | A preset name, or a list: make those presets’ files at build (warm). |
dark | none | The dark file, a path of the same shape (Show a dark version). |
art | none | Other 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
formatssays, 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
srcsetand 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
| Limit | Value | What happens past it |
|---|---|---|
| Pixels in one frame of a source | 268,402,689 (16383 × 16383) | image_too_large at build |
| Pixels over all the frames of an animation | 4,294,967,296 | image_too_large at build |
| A file’s width or height | 99999 pixels | image_prop_invalid at render |
| A share card’s props in a URL | 2048 characters | image_card_props |
| A remote image’s size | remote.maxBytes, 20 MB | refused (413 on request, image_remote_failed at build) |
| A remote fetch’s time | remote.timeout, 10 s | refused (504 on request) |
| Redirects one remote fetch follows | 3 | refused |
| Encodes waiting on a live server | 64, each for 30 s | 503 with image_busy |
| The build cache’s files | 2 GB | the least recently used go |
| A live server’s files on disk | 512 MB | the least recently used go |
| Files kept in memory when the disk fails | 64 MB | the least recently used go |
Entry points and types
| Import | What it holds |
|---|---|
@ogygia/image | Img, getImage, isImage, remoteImage; types ImageDescriptor, ImageFormat, ImageOps, Twin, ImageLayout, ImagePosition, ImagePreset, OutputFormat, Laid, LaidSource, LaidPreload, LayoutRequest, GetImageOptions, RemoteImageOptions. |
@ogygia/image/Img.svelte | The <Img> component alone. |
@ogygia/image/vite | image, sharp, cloudflare, vercel; types ImagePluginOptions, ImageOptions, ImageRemote, ImageTheme, Encoder, SharpOptions, CloudflareOptions, VercelOptions, VercelImages, VercelRemotePattern, and again ImageLayout, ImageOps, ImagePosition, ImagePreset, OutputFormat. |
@ogygia/image/types | The 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.
| Field | What it is |
|---|---|
id | The 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. |
src | The original file’s URL, shipped as an asset. A remoteImage()’s URL; a card’s own-size PNG. |
width | The image’s width in pixels, after its EXIF orientation and ops. |
height | The image’s height in pixels, the same way. |
format | The source’s own format: 'avif', 'webp', 'png', 'jpeg', 'gif', 'svg' or 'tiff'. |
ph | The placeholder, a 16-pixel-wide WebP data: URL. Absent for a transparent image, an SVG, a remoteImage(), a card, or placeholder: false. |
animated | true 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. |
quality | The source’s own quality, when the macro set one. |
ops | The source’s pixel operations, when it has any. |
warm | The presets the build made this source’s files for. |
alt | Alt 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. |
card | A card’s component and props, as its file URLs carry them. |
twins | The 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
| Code | When |
|---|---|
image_no_kit | sveltekit() isn’t in the plugin list. |
image_sharp_missing | sharp isn’t installed and listed, or a server build has it only in devDependencies. |
image_option_unknown | An option key the plugin, a preset, a source or an encoder doesn’t take. |
image_option_invalid | An option with a value that can’t be used, a bad encoder list, or an encoder on the wrong adapter. |
image_macro_arity | The macro got no argument, or more than two. |
image_macro_not_literal | A path or options the build can’t read before the code runs. |
image_query_invalid | An ?og-image import written by hand. |
image_not_found | A path that names no file. |
image_outside_src | An image outside src/, or under src/lib/server/ or a test file. |
image_glob_empty | A glob that matched no file. |
image_decode_failed | A file sharp can’t decode. |
image_too_large | A frame, or an animation, past the pixel limits. |
image_warm_unknown | warm names a preset the config doesn’t declare. |
image_markdown_html | An HTML <img> in markdown that names a local file. |
image_markdown_no_file | A local image in markdown rendered from a string. |
image_path_malformed | A markdown image path whose escapes aren’t UTF-8. |
image_remote_host | A remote URL, or a redirect, on a host remote.hosts doesn’t list. |
image_remote_failed | A remote image the build couldn’t fetch and has no copy of. |
image_card_engine_missing | A card, and satori, satori-html or resvg isn’t installed (or not in dependencies). |
image_card_font | A card font that’s missing, WOFF2, unreadable, or no font at all. |
image_card_css | CSS satori can’t draw (also on request). |
image_card_source | An image a card names that it can’t draw (also on request). |
image_unsettled | A file a prerendered page or a warmed preset names that the build couldn’t make. |
image_mark_left | A prerendered image URL changed so the build can’t find it, or made absolute at Kit’s default origin. |
image_vercel_config | adapter-vercel’s images lacks or opens too much, or vercel() on another adapter. |
image_still_left_out | Warning: the encoders can’t make a moving image’s still. |
image_remote_stale | Warning: a remote image couldn’t be asked again, so the build used its copy. |
At render and on request
| Code | When |
|---|---|
image_preset_unknown | <Img preset> or getImage() names a preset the config doesn’t declare. |
image_prop_invalid | A size, aspect, position, quality or twin no file can have, or a hand-changed descriptor. |
image_remote_invalid | remoteImage() got a bad URL, size, alt or version. |
image_encoder_cannot | A 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_props | A card’s props aren’t JSON, or are too long. |
image_watch_rebuild | A vite build --watch rebuild’s page names a file no build made. |
image_settle_failed | Warning: the endpoint couldn’t make a file and answered 500. |
image_source_changed | Warning: a file asked for an original that has changed since the page rendered; 404. |
image_no_encoder | Warning: this server can’t make files (no sharp) or draw cards; also once at build on an edge adapter. |
image_binding_missing | Warning: the Worker has no Images binding of that name. |
image_busy | Warning: too many files waiting; asks answer 503. |
image_remote_refused | Warning: a remote image was refused (404, 413, 502, 504). |
image_store_write_failed | Warning: the file store couldn’t write; files are kept in memory. |
image_store_unsafe | Warning: the store’s folder isn’t this user’s alone; nothing is kept. |
image_share_format | Warning, 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.
| Code | When |
|---|---|
image_run_refused | The build was handed a notes file outside a runs folder it owns, and went on without it. |
image_run_kept | The build couldn’t delete its run folder. A later build removes it a day later. |
image_folder_refused | The build was handed a store or remote folder it doesn’t own, and used its own. |
image_owed_end | Under --watch on SvelteKit 3, a rebuild started before the last build’s images were all made. |
image_pages_left | Under --watch, pages whose images failed couldn’t all be removed from the output. |