Photon · Native Codecs · Pixel Budgets

Portable image processing for Node agents

A small Node image pipeline with in-process Photon, native codec fallbacks, pixel-budget guards, and typed results for agent-facing media work.

Read the API GitHub
npm install rastermill
JPEGPNGWebPHEICAVIFPhotonsipsImageMagickffmpeg

Rastermill

Fast, portable image processing for Node agents. Rastermill runs in-process with Photon for the common formats and falls back to native tools (sips, ImageMagick, GraphicsMagick, ffmpeg, or the Windows System.Drawing stack) when a format or operation needs an external codec.

import { createRastermill } from "rastermill";

const rastermill = createRastermill({ limits: { inputPixels: 25_000_000 } });

const info = await rastermill.probe(imageBuffer);
const jpeg = await rastermill.encode(imageBuffer, {
  format: "jpeg",
  resize: { maxSide: 1600 },
  quality: 85,
});

Every method accepts a Buffer, Uint8Array, or ArrayBuffer as input.

#Features

PageWhat it covers
ConfigurationcreateRastermill, options, pixel budgets, env vars, custom command resolution
BackendsBackend selection order and automatic fallback
probeRead format, width/height, alpha, and orientation without decoding
encodeResize and re-encode to JPEG, PNG, or WebP, including HEIC/AVIF → JPEG
encodeWithinBytesSearch size/quality/compression under a byte budget
Error handlingRastermillUnavailableError, isRastermillUnavailableError

#Two ways to call

Create a configured instance with createRastermill(options), or use the default-configured module functions: probe, encode, and encodeWithinBytes are exported directly and lazily create a default Rastermill instance on first use.

#Safety model

Rastermill refuses to process images it can't size up. It rejects images with unknown dimensions, inputs larger than limits.inputPixels, and resize targets larger than limits.outputPixels. External tools run with a timeout and a bounded output buffer. See Configuration for the knobs.