ImageScript - v3.0.0

ImageScript

Discord Server Documentation Github NPM


ImageScript is a zero-dependency alternative to common JavaScript bitmap image manipulation tools. Every codec and renderer is written in TypeScript: no WebAssembly, no native binaries, no npm dependencies, no install scripts. The package is about 120 kB (compressed) and runs in Node.js 22.13 or newer (including Alpine/musl, ARM and bundled serverless functions), Deno, Bun and browsers. It works with both import and require(), type definitions are included.

npm install imagescript              # Node.js, Bun and bundlers
deno add jsr:@matmen/imagescript # Deno (npm:imagescript works too)

  • Decoding images
    • PNGs (grayscale, RGB, indexed colors, 1-16 bit, interlaced) with and without alpha channels
    • JPEGs (baseline and progressive; grayscale, RGB, CMYK)
    • TIFFs (strips and tiles; uncompressed, LZW, deflate, PackBits and JPEG compressed; BigTIFF)
    • JPEGs, TIFFs and PNGs are rotated as their Exif (or, for PNGs, XMP) orientation says
  • Decoding GIFs with all frames, durations and disposal modes
  • Rendering SVGs (shapes, paths, gradients, strokes, clip paths, masks, CSS; no text, images or filters)
  • Rendering vector fonts (TrueType and OpenType, with kerning and outlines)
  • Resizing (bilinear, bicubic, area averaging and nearest neighbor)
  • Image manipulation functions (crop , rotate , cropCircle , roundCorners, ...)
  • Filters and color adjustments (blur , sharpen , brightness , hueShift, ...)
  • Compositing with opacity and blend modes (composite)
  • Color information functions (averageColor , dominantColor, ...)
  • Encoding images as PNGs (smallest lossless color type) , JPEGs and animated GIFs

import { Image } from 'imagescript';
import { readFile, writeFile } from 'node:fs/promises';

const image = await Image.decode(await readFile('input.jpg'));
image.resize(256, Image.RESIZE_AUTO).roundCorners(16);
await writeFile('output.png', await image.encode());

With CommonJS:

const { Image } = require('imagescript');

All coordinates are 0-based, (0, 0) is the top left pixel.

A bigger example is the README image generation. Upgrading from 1.x? Version 3 has breaking changes (0-based coordinates, removed WebP encoding, Node.js 22.13+, ...), see the changelog. There is no 2.x release, the number was skipped because of the old experimental imagescript/v2 API.

Example


The deflate/inflate implementation is derived from fflate and the CRC-32 from Fast CRC32 in JavaScript, both by Arjun Barrett. The JPEG codec is based in part on the work of the Independent JPEG Group (libjpeg) and on pdf.js, the glyph rasterizer is translated from font-rs. See THIRD_PARTY_NOTICES.md for their licenses.


If you have any additional questions, feel free to join the discord support server.