77
88---
99
10- ** ImageScript** is a zero-dependency alternative to common JavaScript bitmap image manipulation tools. Every codec and
11- renderer is written in TypeScript: no WebAssembly, no native binaries, no npm dependencies, no install scripts. The
12- package is about 160 kB (compressed) and runs in Node.js 22.13 or newer (including Alpine/musl, ARM and bundled
13- serverless functions), Deno, Bun and browsers. It works with both ` import ` and ` require() ` , type definitions are included.
10+ ** ImageScript** decodes, edits and encodes images in pure TypeScript: no WebAssembly, no native binaries, no
11+ dependencies. It runs in Node.js 22.13+, Deno, Bun and browsers, with ` import ` or ` require() ` , and includes type
12+ definitions.
1413
1514``` sh
1615npm install imagescript # Node.js, Bun and bundlers
17- deno add jsr:@matmen/imagescript # Deno (npm:imagescript works too)
16+ deno add jsr:@matmen/imagescript # Deno
1817```
1918
2019---
2120
22- ### Features
23-
24- - [ Decoding images] ( https://imagescript.matmen.dev/classes/Image.html#decode )
25- - PNGs (grayscale, RGB, indexed colors, 1-16 bit, interlaced) with and without alpha channels
26- - JPEGs (baseline and progressive; grayscale, RGB, CMYK)
27- - TIFFs (strips and tiles; uncompressed, LZW, deflate, PackBits and JPEG compressed; BigTIFF)
28- - WebPs (lossy, lossless and with alpha; bit-exact with libwebp)
29- - BMPs (1-64 bit, with any channel masks, alpha, RLE4 and RLE8, embedded JPEGs and PNGs; also OS/2 bitmaps)
30- - ICOs and CURs (the largest image: bitmaps with their masks, or PNGs)
31- - QOIs
32- - Netpbm images: PBM, PGM, PPM (plain and raw, up to 16 bits), PAM and PFM
33- - Radiance HDRs (RGBE and XYZE, every orientation), tone mapped to sRGB like Reinhard's operator does (or clamped,
34- ` toneMapping ` )
35- - TGAs (color mapped, truecolor and greyscale; uncompressed and run length encoded)
36- - AVIFs (4:2:0, 4:2:2, 4:4:4 and monochrome, 8-12 bit; grids, alpha, crop, rotation and mirroring; the first frame
37- of image sequences; bit-exact with dav1d and libavif), HDR ones (PQ, HLG) tone mapped to sRGB
38- - JPEG XLs (Modular and VarDCT, lossless and lossy, every coding tool: progressive passes and LF frames, patches,
39- splines, noise, restoration filters, upsampling, JPEG recompression, layers and blending, alpha and spot colors,
40- CMYK; animations; within 1 of libjxl's djxl on the conformance suite), XYB ones as sRGB, HDR ones tone mapped to
41- sRGB
42- - JPEGs, TIFFs, PNGs and WebPs are rotated as their Exif (or, for PNGs, XMP) orientation says
43- - images larger than 268 megapixels (` maxPixels ` ) are rejected before decoding, so small files declaring huge images
44- can't exhaust the memory
45- - [ Decoding animations] ( https://imagescript.matmen.dev/classes/Animation.html#decode ) (GIF, APNG, WebP and JPEG XL) with all
46- frames, durations and disposal modes
47- - [ Rendering SVGs] ( https://imagescript.matmen.dev/classes/Image.html#rendersvg ) (shapes, paths, gradients, strokes, clip paths,
48- masks, CSS; no text, images or filters)
49- - [ Rendering vector fonts] ( https://imagescript.matmen.dev/classes/Image.html#rendertext ) (TrueType and OpenType, with
50- complex text shaping in every script, right to left and bidirectional text, outlines, TrueType hinting, fallback
51- fonts and color emoji)
52- - [ Resizing] ( https://imagescript.matmen.dev/classes/Image.html#resize ) (bilinear, bicubic, area averaging and nearest neighbor)
53- - Image manipulation functions ([ crop] ( https://imagescript.matmen.dev/classes/Image.html#crop )
54- , [ region] ( https://imagescript.matmen.dev/classes/Image.html#region )
55- , [ rotate] ( https://imagescript.matmen.dev/classes/Image.html#rotate )
56- , [ cropCircle] ( https://imagescript.matmen.dev/classes/Image.html#cropcircle )
57- , [ roundCorners] ( https://imagescript.matmen.dev/classes/Image.html#roundcorners )
58- , [ trim] ( https://imagescript.matmen.dev/classes/Image.html#trim ) , ...)
59- - Filters and color adjustments ([ blur] ( https://imagescript.matmen.dev/classes/Image.html#blur )
60- , [ sharpen] ( https://imagescript.matmen.dev/classes/Image.html#sharpen )
61- , [ brightness] ( https://imagescript.matmen.dev/classes/Image.html#brightness )
62- , [ hueShift] ( https://imagescript.matmen.dev/classes/Image.html#hueshift ) , ...)
63- - Compositing with opacity and blend modes ([ composite] ( https://imagescript.matmen.dev/classes/Image.html#composite ) ),
64- removing backgrounds ([ colorToAlpha] ( https://imagescript.matmen.dev/classes/Image.html#colortoalpha ) )
65- - Color information functions ([ averageColor] ( https://imagescript.matmen.dev/classes/Image.html#averagecolor )
66- , [ dominantColor] ( https://imagescript.matmen.dev/classes/Image.html#dominantcolor ) , ...)
67- - Encoding images as [ PNGs] ( https://imagescript.matmen.dev/classes/Image.html#encode ) (smallest lossless color type)
68- , [ JPEGs] ( https://imagescript.matmen.dev/classes/Image.html#encodejpeg )
69- , lossless and lossy [ WebPs] ( https://imagescript.matmen.dev/classes/Image.html#encodewebp ) (lossy ones byte for
70- byte like libwebp's cwebp)
71- , [ AVIFs] ( https://imagescript.matmen.dev/classes/Image.html#encodeavif ) (lossy and lossless, with alpha)
72- , [ JPEG XLs] ( https://imagescript.matmen.dev/classes/Image.html#encodejxl ) (lossless byte for byte like libjxl's
73- ` cjxl -e 1 ` , lossy about as small as ` cjxl -e 5 ` )
74- , [ BMPs] ( https://imagescript.matmen.dev/classes/Image.html#encodebmp )
75- , [ QOIs] ( https://imagescript.matmen.dev/classes/Image.html#encodeqoi )
76- , [ Netpbm images] ( https://imagescript.matmen.dev/classes/Image.html#encodepnm ) (PBM, PGM, PPM or PAM, whichever is
77- smallest)
78- and [ TGAs] ( https://imagescript.matmen.dev/classes/Image.html#encodetga )
79- - Encoding animations as [ GIF] ( https://imagescript.matmen.dev/classes/Animation.html#encodegif ) ,
80- [ APNG] ( https://imagescript.matmen.dev/classes/Animation.html#encodeapng ) and lossless or lossy
81- [ WebP] ( https://imagescript.matmen.dev/classes/Animation.html#encodewebp ) , storing only what changes from frame to frame
82-
83- ---
84-
8521### Example
8622
8723``` js
@@ -93,47 +29,59 @@ image.resize(256, Image.RESIZE_AUTO).roundCorners(16);
9329await writeFile (' output.png' , await image .encode ());
9430```
9531
96- With CommonJS:
97-
98- ``` js
99- const { Image } = require (' imagescript' );
100- ```
101-
102- All coordinates are 0-based, ` (0, 0) ` is the top left pixel.
103-
104- A bigger example is the [ README image generation] ( https://github.com/matmen/ImageScript/blob/master/tests/readme.js ) .
105- Upgrading from 1.x? Version 3 has breaking changes (0-based coordinates, lossy WebP encoding as ` encodeWebP({ quality }) ` ,
106- Node.js 22.13+, ...), see the [ changelog] ( https://github.com/matmen/ImageScript/blob/master/CHANGELOG.md ) .
32+ Coordinates are 0-based, ` (0, 0) ` is the top left pixel. A bigger example is the
33+ [ README image generation] ( https://github.com/matmen/ImageScript/blob/master/tests/readme.js ) :
10734
10835[ ![ Example] ( https://github.com/matmen/ImageScript/raw/master/tests/targets/readme.png )] ( https://github.com/matmen/ImageScript/blob/master/tests/readme.js )
10936
11037---
11138
112- ### Benchmarks
39+ ### Features
11340
114- [ bench/] ( bench/README.md ) compares ImageScript to Jimp, image-js, Photon, sharp and @napi-rs/canvas : speed of decoding,
115- encoding, image operations and rendering, encoded file sizes and install sizes. It runs for every release.
41+ | Format | Decode | Encode |
42+ | ---| ---| ---|
43+ | PNG | ✓ | ✓ |
44+ | JPEG | ✓ | ✓ |
45+ | WebP | ✓ | ✓ (lossless and lossy) |
46+ | AVIF | ✓ | ✓ (lossless and lossy) |
47+ | JPEG XL | ✓ | ✓ (lossless and lossy) |
48+ | GIF, APNG (animations) | ✓ | ✓ |
49+ | BMP, QOI, TGA, Netpbm | ✓ | ✓ |
50+ | TIFF, ICO/CUR, Radiance HDR | ✓ | |
51+
52+ Animated WebPs and JPEG XLs decode too, and [ animations] ( https://imagescript.matmen.dev/classes/Animation.html )
53+ encode as GIF, APNG or WebP.
54+
55+ - [ Text rendering] ( https://imagescript.matmen.dev/classes/Image.html#rendertext ) with TrueType and OpenType fonts,
56+ in every script, with color emoji
57+ - [ SVG rendering] ( https://imagescript.matmen.dev/classes/Image.html#rendersvg ) (no text, images or filters)
58+ - [ Resizing] ( https://imagescript.matmen.dev/classes/Image.html#resize ) ,
59+ [ cropping] ( https://imagescript.matmen.dev/classes/Image.html#crop ) ,
60+ [ rotating] ( https://imagescript.matmen.dev/classes/Image.html#rotate ) ,
61+ [ trimming] ( https://imagescript.matmen.dev/classes/Image.html#trim ) ,
62+ [ rounded corners] ( https://imagescript.matmen.dev/classes/Image.html#roundcorners ) , ...
63+ - [ Compositing] ( https://imagescript.matmen.dev/classes/Image.html#composite ) with opacity and blend modes
64+ - Filters and color adjustments: [ blur] ( https://imagescript.matmen.dev/classes/Image.html#blur ) ,
65+ [ sharpen] ( https://imagescript.matmen.dev/classes/Image.html#sharpen ) ,
66+ [ brightness] ( https://imagescript.matmen.dev/classes/Image.html#brightness ) ,
67+ [ hueShift] ( https://imagescript.matmen.dev/classes/Image.html#hueshift ) , ...
68+
69+ See the [ documentation] ( https://imagescript.matmen.dev/ ) for everything else, and the
70+ [ changelog] ( https://github.com/matmen/ImageScript/blob/master/CHANGELOG.md ) when upgrading from an older major version.
71+ [ bench/] ( bench/README.md ) compares ImageScript to Jimp, sharp and others.
11672
11773---
11874
11975### Credits
12076
121- The deflate/inflate implementation is derived from [ fflate] ( https://github.com/101arrowz/fflate ) and the CRC-32 from
122- [ Fast CRC32 in JavaScript] ( https://gist.github.com/101arrowz/e58695f7ccfdf74f60ba22018093edea ) , both by Arjun Barrett.
123- The JPEG codec is based in part on the work of the Independent JPEG Group (libjpeg) and on
124- [ pdf.js] ( https://github.com/mozilla/pdf.js ) , the glyph rasterizer is translated from
125- [ font-rs] ( https://github.com/raphlinus/font-rs ) . The WebP codecs follow [ RFC 9649] ( https://www.rfc-editor.org/rfc/rfc9649 ) and [ RFC 6386] ( https://www.rfc-editor.org/rfc/rfc6386 )
126- and reproduce [ libwebp] ( https://chromium.googlesource.com/webm/libwebp ) 's color conversion, the lossy WebP encoder is
127- ported from libwebp's, the TrueType hinting follows
128- [ FreeType] ( https://freetype.org ) 's interpreter (portions of this software are copyright © 2026 The FreeType Project),
129- the text shaping is ported from [ HarfBuzz] ( https://github.com/harfbuzz/harfbuzz ) and uses data of the
130- [ Unicode Character Database] ( https://www.unicode.org/ucd/ ) . The AV1 decoder is ported from
131- [ dav1d] ( https://code.videolan.org/videolan/dav1d ) , AVIFs are converted to RGB like
132- [ libavif] ( https://github.com/AOMediaCodec/libavif ) does, the JPEG XL decoder is ported from
133- [ jxl-oxide] ( https://github.com/tirr-c/jxl-oxide ) and [ libjxl] ( https://github.com/libjxl/libjxl ) , the JPEG XL encoders
134- follow libjxl's fast lossless encoder and its lossy heuristics, the AV1 encoder mirrors the decoder and uses libaom's symbol encoder.
135- See [ THIRD_PARTY_NOTICES.md] ( THIRD_PARTY_NOTICES.md ) for their licenses.
77+ ImageScript builds on [ fflate] ( https://github.com/101arrowz/fflate ) , libjpeg, [ pdf.js] ( https://github.com/mozilla/pdf.js ) ,
78+ [ font-rs] ( https://github.com/raphlinus/font-rs ) , [ libwebp] ( https://chromium.googlesource.com/webm/libwebp ) ,
79+ [ HarfBuzz] ( https://github.com/harfbuzz/harfbuzz ) , [ dav1d] ( https://code.videolan.org/videolan/dav1d ) ,
80+ [ libavif] ( https://github.com/AOMediaCodec/libavif ) , libaom, [ jxl-oxide] ( https://github.com/tirr-c/jxl-oxide ) and
81+ [ libjxl] ( https://github.com/libjxl/libjxl ) . The TrueType hinting follows [ FreeType] ( https://freetype.org ) : portions of
82+ this software are copyright © 2026 The FreeType Project (www.freetype.org ). All rights reserved. See
83+ [ THIRD_PARTY_NOTICES.md] ( THIRD_PARTY_NOTICES.md ) for the licenses.
13684
13785---
13886
139- If you have any additional questions, feel free to join the [ discord support server] ( https://discord.gg/8hPrwAH ) .
87+ Questions? Join the [ Discord server] ( https://discord.gg/8hPrwAH ) .
0 commit comments