Skip to main content

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:
A single 25MP image upload can crash your edge function without sip’s streaming approach.
sip’s solution:
  1. DCT Scaling - Decode JPEG at 1/2, 1/4, or 1/8 scale during decompression
  2. Scanline Streaming - Process one row at a time (~50KB peak for any image size)
  3. Native WASM - libjpeg-turbo and libspng compiled to WebAssembly

Installation

npm
pnpm
yarn
JPEG and PNG processing requires the WASM module to be built. See WASM Build below.

Quick Start

Functions

probe

Detect image format and dimensions by reading only the header bytes. No full decode occurs.
Parameters: Returns: ProbeResult
Format Detection:

sip.process

Process an image: decode, resize, and encode to JPEG.
Parameters: Options: Returns: Promise<ProcessResult>
Behavior:
  • Aspect Ratio: Always preserved. Output fits within maxWidth×maxHeight box
  • Quality Reduction: If output exceeds maxBytes, retries with lower quality
  • Size Reduction: If still over maxBytes at minimum quality, resizes smaller

initStreaming

Initialize the WASM module. Optional but recommended for reducing first-call latency.
Returns: 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:
Memory per row (2000px width): ~24KB total, constant regardless of image height.

WASM Build

Prerequisites

Install the Emscripten SDK:

Building

This will:
  1. Download libjpeg-turbo, libspng, and miniz to wasm/libs/
  2. Compile with Emscripten
  3. Output dist/sip.js and dist/sip.wasm
The WASM files are not committed to git. Your CI/CD pipeline must run pnpm build: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

No PNG, WebP, or AVIF output. All processed images become JPEG.
Transparency is discarded. PNG/WebP with alpha become opaque JPEG.
Without WASM, JPEG and PNG processing throws an error. WebP and AVIF still work but use more memory.
The output may slightly exceed maxBytes. The algorithm tries quality reduction first, then dimension reduction.
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