@cross/image

A pure JavaScript, dependency-free, cross-runtime image processing library for Deno, Node.js, and Bun.

Features

  • 🚀 Pure JavaScript - No native dependencies
  • 🔌 Pluggable formats - Easy to extend with custom formats
  • 📦 Cross-runtime - Works on Deno, Node.js (18+), and Bun
  • 🎨 Multiple formats - PNG, APNG, JPEG, WebP, GIF, TIFF, BMP, ICO, DNG, PAM, PPM, PCX and ASCII support
  • ✂️ Image manipulation - Resize, crop, composite, and more
  • 🎛️ Image processing - Chainable filters including brightness, contrast, saturation, exposure, blur, sharpen, sepia, and more
  • 🖌️ Drawing operations - Create, fill, and manipulate pixels
  • 🧩 Multi-frame - Decode/encode animated GIFs, APNGs and multi-page TIFFs
  • 🔧 Simple API - Easy to use, intuitive interface

Installation

Deno

import { Image } from "jsr:@cross/image";

Node.js

npm install cross-image
import { Image } from "cross-image";

Bun

npm install cross-image
import { Image } from "cross-image";

Quick Start

Deno

import { Image } from "@cross/image";

// Decode an image (auto-detects format)
const data = await Deno.readFile("input.png");
const image = await Image.decode(data);

console.log(`Image size: ${image.width}x${image.height}`);

// Create a new blank image
const canvas = Image.create(800, 600, 255, 255, 255);

// Composite the loaded image on top
canvas.composite(image, 50, 50);

// Apply image processing
canvas
  .brightness(0.1)
  .contrast(0.2)
  .saturation(-0.1);

// Encode the result
const jpeg = await canvas.encode("jpeg");
await Deno.writeFile("output.jpg", jpeg);

Node.js

import { Image } from "cross-image";
import { readFile, writeFile } from "node:fs/promises";

// Read an image (auto-detects format)
const data = await readFile("input.png");
const image = await Image.decode(data);

console.log(`Image size: ${image.width}x${image.height}`);

// Resize the image
image.resize({ width: 800, height: 600 });

// Save the result
const jpeg = await image.encode("jpeg");
await writeFile("output.jpg", jpeg);

Documentation

Supported Formats

@cross/image supports 10 image formats with varying levels of pure-JS implementation:

  • PNG, BMP, GIF, DNG, PAM, PCX, ASCII - Full pure-JS implementation
  • JPEG - Pure-JS baseline DCT, native API for progressive
  • WebP - Pure-JS lossless, native API for lossy VP8
  • TIFF - Pure-JS uncompressed + LZW, native API for other compressions

See the Format Support page for detailed compatibility information.

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request on GitHub.