@ogygia/image · API
@ogygia/image/vite
The image() plugin, its options and the sharp(), cloudflare() and vercel() encoders.
On this page
- cloudflare
- image
- sharp
- vercel
- CloudflareOptions
- CloudflareOptions.links
- CloudflareOptions.binding
- Encoder
- Encoder.name
- Encoder.links
- Encoder.maker
- Encoder.binding
- Encoder.negotiates
- Encoder.widths
- Encoder.qualities
- Encoder.effort
- ImageOps
- ImageOps.rotate
- ImageOps.flip
- ImageOps.flop
- ImageOps.grayscale
- ImageOps.blur
- ImageOps.sharpen
- ImageOps.normalize
- ImageOps.negate
- ImageOps.gamma
- ImageOps.tint
- ImageOps.modulate
- ImageOptions
- ImageOptions.quality
- ImageOptions.placeholder
- ImageOptions.ops
- ImageOptions.warm
- ImageOptions.dark
- ImageOptions.art
- ImagePluginOptions
- ImagePluginOptions.quality
- ImagePluginOptions.formats
- ImagePluginOptions.placeholder
- ImagePluginOptions.breakpoints
- ImagePluginOptions.presets
- ImagePluginOptions.markdown
- ImagePluginOptions.encoder
- ImagePluginOptions.theme
- ImagePluginOptions.remote
- ImagePreset
- ImagePreset.layout
- ImagePreset.width
- ImagePreset.height
- ImagePreset.aspect
- ImagePreset.position
- ImagePreset.sizes
- ImagePreset.priority
- ImagePreset.placeholder
- ImagePreset.morph
- ImagePreset.quality
- ImagePreset.formats
- ImagePreset.art
- ImageRemote
- ImageRemote.hosts
- ImageRemote.maxBytes
- ImageRemote.timeout
- ImageRemote.maxAge
- ImageTheme
- ImageTheme.dark
- ImageTheme.light
- SharpOptions
- SharpOptions.effort
- VercelImages
- VercelImages.sizes
- VercelImages.qualities
- VercelImages.formats
- VercelImages.domains
- VercelImages.localPatterns
- VercelImages.remotePatterns
- VercelOptions
- VercelOptions.sizes
- VercelOptions.qualities
- VercelRemotePattern
- VercelRemotePattern.protocol
- VercelRemotePattern.hostname
- VercelRemotePattern.port
- ImageLayout
- ImagePosition
- OutputFormat
This page is generated from the package’s own .d.ts files on every build, so the signatures, descriptions and examples below always match the source. Options explains every option, preset key and descriptor field in one place.
Exports cloudflare · image · sharp · vercel · CloudflareOptions · Encoder · ImageOps · ImageOptions · ImagePluginOptions · ImagePreset · ImageRemote · ImageTheme · SharpOptions · VercelImages · VercelOptions · VercelRemotePattern · ImageLayout · ImagePosition · OutputFormat
import { … } from '@ogygia/image/vite';cloudflare
function
Cloudflare, for an app on Workers (adapter-cloudflare): a page rendered on request names its
files as Image Transformations links, and what links cannot name (or every file, with links: false) the app's endpoint makes with the Worker's Images binding, kept in the Worker's
cache. A prerendered page's files are made by the build, with sharp, as with any encoder.
function cloudflare(options?: CloudflareOptions): Encoder;function image(options?: ImagePluginOptions): Plugin[];sharp
function
sharp (the default): the app's own endpoint makes every live file, in dev and on a Node server,
and the build every file a prerendered page names. effort.avif trades build time for
smaller AVIF files.
function sharp(options?: SharpOptions): Encoder;vercel
function
Vercel, for an app on adapter-vercel: a page rendered on request names each file as an Image
Optimization link, /_vercel/image?url=…&w=…&q=…, made by Vercel's CDN, which only resizes
(no crop, position or operation) and picks AVIF or WebP from the browser. Hand its images to
the adapter (adapter({ images: encoder.images })); the build checks the adapter's output has
them. List sharp() after it ([vercel(), sharp()]) for the files Vercel cannot make, or they
fail to render. A prerendered page's files are made by the build, with sharp, as with any
encoder.
function vercel(options?: VercelOptions): Encoder & {
readonly images: VercelImages;
};CloudflareOptions
interface
What cloudflare() takes.
CloudflareOptions.links
Name each file a page rendered on request shows as an Image Transformations link, /cdn-cgi/image/<options>/<original>, made by Cloudflare's CDN (transformations must be on
for the zone). Default true. false: the app's endpoint makes each with the Images
binding.
CloudflareOptions.binding
The Images binding the endpoint makes files with: the name the Worker's wrangler config
gives it ("images": { "binding": "IMAGES" }). Default 'IMAGES'.
interface CloudflareOptions {/*…*/}links?: boolean;binding?: string;Encoder
interface
Who makes an app's image files, and what URL names each: plain data from a factory
(sharp(), cloudflare(), vercel()), for image({ encoder }).
Encoder.name
Which encoder it is.
Encoder.links
What its own links can make without the app's endpoint, or null: every live file goes through the endpoint.
Encoder.maker
What makes its files at the app's endpoint, or null: nothing in that runtime.
Encoder.binding
The Cloudflare Images binding its maker makes files with, or null.
Encoder.negotiates
Whether a CDN picks each file's format from the browser's Accept (one URL per width).
Encoder.widths
The widths it makes: any, or only these.
Encoder.qualities
The qualities it makes: any, or only these.
Encoder.effort
How hard sharp works on each format, for sharp() (null for the others): AVIF 0 to 9.
interface Encoder {/*…*/}readonly name: "sharp" | "cloudflare" | "vercel";readonly links: readonly Need[] | null;readonly maker: "sharp" | "binding" | null;readonly binding: string | null;readonly negotiates: boolean;readonly widths: "any" | readonly number[];readonly qualities: "any" | readonly number[];readonly effort: {
readonly avif: number;
} | null;ImageOps
interface
Pixel operations a source carries (the macro's ops), applied before any resize or crop, in this
order. Each is sharp's operation of that name.
ImageOps.rotate
ImageOps.flip
ImageOps.flop
ImageOps.grayscale
ImageOps.blur
ImageOps.sharpen
ImageOps.normalize
ImageOps.negate
ImageOps.gamma
ImageOps.tint
ImageOps.modulate
interface ImageOps {/*…*/}rotate?: number;flip?: boolean;flop?: boolean;grayscale?: boolean;blur?: number;sharpen?: boolean;normalize?: boolean;negate?: boolean;gamma?: number;tint?: string;modulate?: {
brightness?: number;
saturation?: number;
hue?: number;
lightness?: number;
};ImageOptions
interface
One source's options: what belongs to the file, whatever page shows it.
ImageOptions.quality
Encoder quality, 1–100, for every file made from this source. Default: 60 for AVIF, 80 for the others.
ImageOptions.placeholder
Paint a blur placeholder until the image arrives. Default true (never for a transparent
image or an SVG).
ImageOptions.ops
Pixel operations, applied before any resize or crop.
ImageOptions.warm
Make these presets' files at build ('cover', or ['cover', 'thumb']), for a page rendered
on a live server: <Img preset="cover"> of this source then names static files the build
made instead of asking the endpoint. A prerendered page needs none: its render asks already.
ImageOptions.dark
The image's dark file ('./chart-dark.png', relative to this file), shown when the visitor's
theme is dark. It must have the same shape, so the page keeps its box when the theme flips.
ImageOptions.art
The designer's other files, by the media condition each is shown at
({ '(max-width: 600px)': './hero-tall.jpg' }), each with its own shape and box.
interface ImageOptions {/*…*/}quality?: number;placeholder?: boolean;ops?: ImageOps;warm?: string | string[];dark?: string;art?: Record<string, string>;ImagePluginOptions
interface
The plugin's options: every image's defaults, the presets, and markdown's.
ImagePluginOptions.quality
ImagePluginOptions.formats
The formats to offer, best first. Default ['avif', 'webp']. An animated image is offered as
animated WebP whatever this says.
ImagePluginOptions.placeholder
ImagePluginOptions.breakpoints
The width ladder a responsive image is offered at (capped at the image's own width; a step
within a tenth of a width the layout names is left out). Default [320, 480, 640, 960, 1280, 1600, 2048].
ImagePluginOptions.presets
Named ways to show an image, chosen with <Img preset="…"> (own props say over them): { thumb: { width: 400, aspect: '1/1' }, cover: { layout: 'fullWidth', aspect: '16/9',
priority: true } }. A markdown body image uses prose when there is one.
ImagePluginOptions.markdown
Markdown images (with @ogygia/content): width is the prose column's width, in CSS pixels,
when there is no prose preset; animated names the preset a moving image (an animated GIF
or WebP) takes instead, with its own width and sizes; false leaves markdown images as
plain <img>. Default {} (each image as wide as itself).
ImagePluginOptions.encoder
Who makes the image files, and what URL names each: an encoder from @ogygia/image/vite, or
a list in order of priority: the first that can make a file makes it ([vercel(), sharp()]).
A list holds one platform, at most one encoder that makes files at the endpoint, and sharp() only last; any other fails the build. Default sharp(): the app's own endpoint makes every live file. A
prerendered page's files are made by the build, with sharp, whatever this says.
ImagePluginOptions.theme
An app with a theme switch: the selectors its dark and light themes are written by. A
source with a dark file then renders two <picture>s, and the plugin's stylesheet shows the
dark one when the dark selector matches, or when the system prefers dark and the light
selector does not. Without it, the system's setting alone picks.
ImagePluginOptions.remote
Images on other hosts: import.meta.og.image('https://images.example.com/a.jpg'), and in
markdown a body image or frontmatter URL on a listed host. Each is fetched at build into
the build cache, asked again on every build (an unchanged one is not downloaded again), and
from there it is a file of the app's own.
interface ImagePluginOptions {/*…*/}quality?: number;formats?: OutputFormat[];placeholder?: boolean;breakpoints?: number[];presets?: Record<string, ImagePreset>;markdown?: {
width?: number;
animated?: string;
} | false;encoder?: Encoder | Encoder[];theme?: ImageTheme;remote?: ImageRemote;ImagePreset
interface
How a page shows an image: what a preset names, and what <Img>'s own props say over it.
ImagePreset.layout
ImagePreset.width
Display width, CSS pixels.
ImagePreset.height
Display height, CSS pixels. With width, the box the image is cropped to.
ImagePreset.aspect
The box's shape, width / height (16 / 9, or '16/9'): the files are cropped to it.
ImagePreset.position
Where a crop keeps. Default center.
ImagePreset.sizes
Replaces the sizes the layout derives.
ImagePreset.priority
The page's main image (its LCP): loads first, preloaded from the head.
ImagePreset.placeholder
Paint the blur placeholder until the image arrives. Default true.
ImagePreset.morph
Name the image for a view transition by its source, so on a client-side navigation it glides into the same source on the next page (a thumbnail into the post's hero). At most one per source on a page: a name that repeats cancels the page's transition.
ImagePreset.quality
Encoder quality, 1–100.
ImagePreset.formats
The formats to offer, best first.
ImagePreset.art
Art direction: another crop at another media condition, each laid out with its own box
([{ media: '(max-width: 600px)', aspect: '4/5', position: 'attention' }]). The first whose
media matches is shown. An <Img art> of its own replaces these.
interface ImagePreset {/*…*/}layout?: ImageLayout;width?: number;height?: number;aspect?: number | string;position?: ImagePosition;sizes?: string;priority?: boolean;placeholder?: boolean;morph?: boolean;quality?: number;formats?: OutputFormat[];art?: Twin[];ImageRemote
interface
Where the build may fetch images from, and how much it takes.
ImageRemote.hosts
The hosts the app takes images from: 'images.example.com', '*.cdn.example.com' (every
name below it), with a port when not the default; https:// only, unless an entry starts
with http:// ('http://127.0.0.1:4100'). Any other URL fails the build
(image_remote_host), and stays a plain <img> in markdown.
ImageRemote.maxBytes
The most bytes one image may have. Default 20 MB (20_000_000).
ImageRemote.timeout
How long one fetch may take, in ms, its redirects and body included. Default 10_000.
ImageRemote.maxAge
How long, in seconds, a file made on request from a URL known only at request may be kept.
Default one day (86_400).
interface ImageRemote {/*…*/}hosts: string[];maxBytes?: number;timeout?: number;maxAge?: number;ImageTheme
interface
How the app writes its theme, as two CSS selectors that match the root when each theme is
chosen ({ dark: ':root[data-theme="dark"]', light: ':root[data-theme="light"]' }).
ImageTheme.dark
ImageTheme.light
interface ImageTheme {/*…*/}dark: string;light: string;SharpOptions
interface
What sharp() takes.
SharpOptions.effort
How hard sharp works on a file, per format: avif a whole number from 0 (fastest) to 9
(smallest). Default { avif: 2 }: about twice as fast as 4, for files about 0.2% larger.
interface SharpOptions {/*…*/}effort?: {
avif?: number;
};VercelImages
interface
The adapter-vercel images config vercel() hands over, as adapter({ images }) takes it.
VercelImages.sizes
VercelImages.qualities
VercelImages.formats
VercelImages.domains
VercelImages.localPatterns
The only paths the optimizer may read: the app's originals (/_app/immutable/assets/; the
build says the value to pass for another paths.base or appDir).
VercelImages.remotePatterns
The only hosts it may fetch from: those image({ remote: { hosts } }) lists, for a remoteImage(). vercel() cannot know them: add them as the build says
(image_vercel_config, one entry per host).
interface VercelImages {/*…*/}readonly sizes: number[];readonly qualities: number[];readonly formats: ("image/avif" | "image/webp")[];readonly domains: string[];readonly localPatterns: {
pathname: string;
search: string;
}[];readonly remotePatterns?: VercelRemotePattern[];VercelOptions
interface
What vercel() takes.
VercelOptions.sizes
The widths Vercel may make (its images.sizes): every width a page asks for is snapped up to
one of these. Default: 16, 32, 48, 64, 96, 128, 256 and 384 (fixed and small images), then
the plugin's default breakpoints.
VercelOptions.qualities
The qualities Vercel may make (its images.qualities), 1–100. Default: 60 and 80, the
qualities AVIF and WebP files are made at when nothing says one. A plugin or preset quality must be one of these (the build fails otherwise); a file asking for another is not Vercel's
to make.
interface VercelOptions {/*…*/}sizes?: number[];qualities?: number[];VercelRemotePattern
interface
One images.remotePatterns entry: a scheme, a host pattern, a port.
VercelRemotePattern.protocol
VercelRemotePattern.hostname
VercelRemotePattern.port
interface VercelRemotePattern {/*…*/}readonly protocol: "http" | "https";readonly hostname: string;readonly port?: string;ImageLayout
type
How the image sits on the page:
constrained(default): as wide aswidth(the intrinsic width when left out), shrinking with its container.fullWidth: the container's whole width, whatever the screen.fixed: exactlywidth×heightCSS pixels, at 1× and 2× density.
type ImageLayout = "constrained" | "fullWidth" | "fixed";ImagePosition
type
Where a crop keeps: an edge, the centre, or sharp's smart crops (attention: the most striking
part; entropy: the busiest).
type ImagePosition = "center" | "centre" | "top" | "bottom" | "left" | "right" | "attention" | "entropy";type OutputFormat = "avif" | "webp" | "png" | "jpeg";