ImageScript decodes, edits and encodes images in pure TypeScript: no WebAssembly, no native binaries, no runtime dependencies. It runs on Node.js 22.13+, Deno, Bun, browsers and edge runtimes, and ships with TypeScript type definitions.
npm install imagescript # Node.js, Bun and bundlers
deno add jsr:@matmen/imagescript # DenoUpgrading from 3.x? Read Migrating to 4.0 first.
import { Image } from 'imagescript';
import { readFile, writeFile } from 'node:fs/promises';
const image = await Image.decode(await readFile('input.jpg'));
image.resize({ width: 256 }).roundCorners({ radius: 16 });
await writeFile('output.png', await image.encodePNG());The same code runs everywhere, only reading and writing the bytes differs. Image.decode() takes any ArrayBuffer or
typed array (fetch(url).then(r => r.arrayBuffer()) in a browser or on an edge runtime, Deno.readFile(),
Bun.file().arrayBuffer()), and the encoders return a Uint8Array. In a browser without a bundler, import it from jsDelivr:
import { Image } from 'https://cdn.jsdelivr.net/npm/imagescript@4/+esm';The codecs that can use worker threads (large AVIF and JPEG XL images, lossless WebP; the threads option) do so in
Node.js, Deno and Bun, and in browsers on cross-origin isolated pages. Large PNGs are compressed in parallel on the zlib
threads of Node.js (4 unless UV_THREADPOOL_SIZE says otherwise) and Bun instead, without a threads option. Where
workers can't start, the work runs on the calling thread: the output is the same, only slower, and nothing warns about
it. Browsers refuse workers from another origin, so the jsDelivr import above runs single-threaded; serve the package
from your own origin (on a cross-origin isolated page) to get threads.
Bundlers that write one file (esbuild, Rollup, bun build) don't copy the worker's module: serve dist/util/worker.js next to the
bundle, or the same single-threaded fallback is used. webpack and Vite emit it.
| Format | Decode | Encode |
|---|---|---|
| PNG | ✓ | ✓ |
| JPEG | ✓ | ✓ |
| WebP | ✓ | ✓ (lossless and lossy) |
| AVIF | ✓ | ✓ (lossless and lossy) |
| JPEG XL | ✓ | ✓ (lossless and lossy) |
| GIF, APNG (animations) | ✓ | ✓ |
| BMP, QOI, TGA, Netpbm | ✓ | ✓ |
| TIFF, ICO/CUR, Radiance HDR | ✓ | |
| HDR gain maps (brighter highlights on HDR displays; JPEG, AVIF, JPEG XL) | ✓ | ✓ |
Animations can be decoded from GIF, APNG, WebP and JPEG XL,
and encoded as GIF, APNG or WebP, all at once or
frame by frame. Lossless encoding keeps every pixel
exactly; lossy encoding makes smaller files by approximating some image detail. quality: 100 is lossless for WebP,
AVIF and JPEG XL (JPEG has no lossless mode). Without a quality, WebP and JPEG XL are lossless and AVIF is lossy.
Not supported (decoding them throws an error): CCITT-compressed TIFF and arithmetic-coded JPEG. Lossless JPEG XL is fast but not small: for small lossless files, PNG or WebP are the better choice.
Embedded color profiles are converted to sRGB, the standard color format for most screens, where supported. CMYK and lookup-table profiles are left unchanged.
Supported image operations preserve gain maps; editing pixels directly with image.bitmap or setPixelAt() does not.
- Text rendering with TrueType, OpenType and WOFF fonts (not WOFF2; some OpenType outline formats are unsupported): right-to-left text and scripts where letters connect or combine, plus color emoji and variable TrueType fonts
- SVG rendering, including text (with fonts you pass or fonts embedded in the SVG); no automatic fetching of external images or fonts
- Resizing, cropping, rotating, trimming, rounded corners, ...
- Compositing with opacity and blend modes
- Filters and color adjustments: blur, sharpen, brightness, hueShift, ...
The documentation covers the full API. When upgrading from an older major version, see the changelog. bench/ compares ImageScript's speed and file sizes with Jimp, sharp and other libraries.
ImageScript builds on fflate, libjpeg, pdf.js, font-rs, libwebp, HarfBuzz, dav1d, libavif, libaom, jxl-oxide and libjxl. The TrueType hinting follows FreeType: portions of this software are copyright © 2026 The FreeType Project (www.freetype.org). All rights reserved. See THIRD_PARTY_NOTICES.md for the licenses.
