probe
Inspect an image without a full decode.
const info = await rastermill.probe(input);
// => { format, width, height, bytes, hasAlpha, orientation } | null
probe reads the file header to report the format and dimensions, plus an alpha hint and EXIF orientation when the format exposes them. It is cheap: for the formats Rastermill recognizes by header (png, jpeg, gif, webp, bmp, tiff, heif, avif) it never runs a decoder.
#Result
type ImageProbe = {
format: ImageFormat; // "png" | "jpeg" | "gif" | "webp" | "bmp" | "tiff" | "heif" | "avif"
width: number;
height: number;
bytes: number;
hasAlpha: boolean | null; // null when the header can't tell
orientation: number | null; // EXIF orientation 1–8, or null
};
hasAlphaisfalsefor JPEG and simple lossy WebP. For PNG, lossless WebP (VP8L), and extended WebP (VP8X), it reports the header's alpha hint. For GIF, BMP, TIFF, HEIF, and AVIF, it isnull.orientationreports JPEG EXIF and TIFF orientation tags, or the equivalent HEIF/AVIF primary-image transform, when present.- For linked TIFF pages, dimensions and orientation describe the largest page. This keeps the input pixel-budget check conservative;
encodewrites the first page using that page's own dimensions and orientation.
#Lenient by design
probe returns null — it does not throw — when the input is undecodable or its dimensions exceed limits.inputPixels. Encoding the same input still throws (see Error handling), so use probe for "can I look at this?" and encode for "process this."
const info = await rastermill.probe(buffer);
if (!info) return; // unknown format or over the input budget
if (info.hasAlpha) {
const alpha = await rastermill.transparency(buffer);
// Use alpha.hasAlphaChannel or alpha.hasTransparentPixels for policy.
}
#Header-only helpers
readImageProbeFromHeader(input) and readImageMetadataFromHeader(input) are exported as synchronous, budget-free header parsers. probe builds on the former and adds the configured pixel-budget check.