$ show openclaw/rastermill
Rastermill is a Node.js image processing library that provides a unified API for probing, transparency inspection, and encoding (resize, convert, byte-budget search). It uses Photon (WASM) in-process for common formats (PNG, JPEG, GIF, WebP, BMP) and falls back to native tools (sips, ImageMagick, GraphicsMagick, ffmpeg, Windows System.Drawing) for formats like HEIC/AVIF or when quality-controlled WebP is needed. The library enforces pixel budgets to prevent decompression bombs, strips metadata by default, handles EXIF/HEIF orientation, and supports cancellation via AbortSignal. It is designed for server-side and agent-facing media pipelines. The codebase is a single well-structured TypeScript module with comprehensive tests and CI coverage.
The LLM identified 3 files worth highlighting for reuse:
The exported function `readImageProbeFromHeader` is a synchronous, zero-dependency header parser that extracts format, dimensions, alpha hints, and orientation from PNG, JPEG, GIF, WebP, BMP, TIFF, HEIF, and AVIF files without decoding pixels. It can be extracted and reused in any Node.js project that needs fast image metadata inspection.
The exported function `encodePngRgba` encodes raw RGBA pixel data into a PNG buffer with configurable compression level. It is self-contained (uses only Node.js zlib) and can be reused independently for generating PNG images from pixel arrays.
The internal `encodeWithBudget` method implements a multi-axis search (dimensions, quality, compression) to fit encoded output within a byte or base64 budget. The algorithm iterates over candidate settings in descending order and returns the smallest candidate if no exact fit is found. This pattern is reusable for any encoding task that needs to meet size constraints.