Overview
The@standardagents/sip package (Small Image Processor) provides memory-efficient image processing designed for memory-constrained edge computing environments.
Key Features
- Process 100MP+ images with less than 1MB peak memory
- DCT-based scaling for JPEG (decode at reduced resolution)
- Scanline-by-scanline processing (never holds full image in memory)
- Native WASM codecs (libjpeg-turbo, libspng)
- Works in edge runtimes, browsers, and Node.js
Why sip?
Edge computing environments typically have strict memory limits (e.g., 128MB). Traditional image processing libraries decode the entire image into memory:
sip’s solution:
- DCT Scaling - Decode JPEG at 1/2, 1/4, or 1/8 scale during decompression
- Scanline Streaming - Process one row at a time (~50KB peak for any image size)
- Native WASM - libjpeg-turbo and libspng compiled to WebAssembly
Installation
npm
pnpm
yarn
Quick Start
Functions
probe
Detect image format and dimensions by reading only the header bytes. No full decode occurs.
Returns:
ProbeResult
sip.process
Process an image: decode, resize, and encode to JPEG.
Options:
Returns:
Promise<ProcessResult>
- Aspect Ratio: Always preserved. Output fits within
maxWidth×maxHeightbox - Quality Reduction: If output exceeds
maxBytes, retries with lower quality - Size Reduction: If still over
maxBytesat minimum quality, resizes smaller
initStreaming
Initialize the WASM module. Optional but recommended for reducing first-call latency.Promise<boolean> - true if WASM loaded successfully.
Format Support
Input Formats
Output Format
Output is always JPEG. This simplifies the encoder and provides universal browser compatibility.
Memory Model
DCT Scaling (JPEG only)
JPEG uses Discrete Cosine Transform (DCT) for compression. libjpeg-turbo can decode at reduced resolution during decompression:
Example: 6800×4500 image (30.6MP)
sip automatically selects the optimal scale based on target dimensions.
Scanline Streaming
Instead of decoding the entire image, sip processes row-by-row:WASM Build
Prerequisites
Install the Emscripten SDK:Building
- Download libjpeg-turbo, libspng, and miniz to
wasm/libs/ - Compile with Emscripten
- Output
dist/sip.jsanddist/sip.wasm
Configuration Examples
Recommended Settings by Use Case:Examples
Thumbnail Generation
Upload Handler with Validation
Edge Function Integration
Multiple Size Generation
TypeScript Support
The package includes full TypeScript definitions:Limitations
Output is always JPEG
Output is always JPEG
No PNG, WebP, or AVIF output. All processed images become JPEG.
No alpha channel preservation
No alpha channel preservation
Transparency is discarded. PNG/WebP with alpha become opaque JPEG.
WASM required for JPEG/PNG
WASM required for JPEG/PNG
Without WASM, JPEG and PNG processing throws an error. WebP and AVIF still work but use more memory.
maxBytes is best-effort
maxBytes is best-effort
The output may slightly exceed
maxBytes. The algorithm tries quality reduction first, then dimension reduction.No EXIF rotation
No EXIF rotation
EXIF orientation is not applied. Handle EXIF separately if needed.
Error Handling
Comparison with Alternatives
*@cf-wasm/photon requires paid bindings for large images in some edge environments.
Next Steps
React SDK
Build UIs that connect to agent threads
Tools
Create tools that process images