npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rosetta-squint-decode

v1.1.0

Published

Byte-exact PIL-compatible image decoder library (JS/TS). Part of rosetta-squint.

Readme

rosetta-squint-decode — JS/TS port

Byte-exact PIL-compatible image decoder library, JS/TS port (ESM, Node 18+).

Decodes BMP, PNG, GIF (first frame), JPEG, WebP, TIFF, and HEIC to a raw RGB or RGBA byte buffer matching what PIL.Image.open(...).tobytes() produces. No system libraries required — everything bundles natively or as WASM.

Quick start

import { readFileSync } from "node:fs";
import {
    decode, detectFormat, supportedFormats, DecodeError,
} from "rosetta-squint-decode";

const bytes = new Uint8Array(readFileSync("photo.jpg"));

const sniff = detectFormat(bytes);              // "jpeg" | "png" | ... | null
console.log("detected:", sniff);

try {
    const img = await decode(bytes);            // async — WASM init
    console.log(`${img.width}x${img.height} channels=${img.channels} format=${img.format}`);
    // img.data is Uint8Array, length = width * height * (3 or 4)
} catch (e) {
    if (e instanceof DecodeError) {
        console.error("decode failed:", e.kind, e.detail);
    } else {
        throw e;
    }
}

Note: decode() is async. The JPEG, WebP, and HEIC backends are WASM modules that initialize asynchronously. Always await.

Build + test

npm install
npm test                    # 44 tests via vitest, all passing on Linux x86-64
npm run build               # tsc → dist/

Tests resolve fixtures and goldens from ../../spec/. Run from this package root.

API

function decode(bytes: Uint8Array): Promise<DecodedImage>;
function detectFormat(bytes: Uint8Array): Format | null;
function supportedFormats(): Format[];

interface DecodedImage {
    width: number;
    height: number;
    data: Uint8Array;             // row-major, length = width * height * (3 or 4)
    channels: 3 | 4;
    format: Format;
}

type Format = "bmp" | "png" | "gif" | "jpeg" | "webp" | "tiff" | "heic";
type DecodeErrorKind =
    | "unsupportedFormat"
    | "corruptInput"
    | "truncated"
    | "unsupportedFeature";

class DecodeError extends Error {
    kind: DecodeErrorKind;
    format: Format | null;
    detail: string;
}

Dependencies

Runtime (all in package.json):

  • pngjs ^7 — pure-JS PNG
  • omggif ^1 — pure-JS GIF
  • utif2 ^4.1.0 — pure-JS TIFF
  • @jsquash/jpeg ^1.6.0 — mozjpeg compiled to WASM
  • @jsquash/webp ^1.5.0 — libwebp compiled to WASM
  • libheif-js ^1.17.1 — libheif + libde265 compiled to WASM

BMP is implemented inline (no third-party library).

Install

Not on npm yet. From a sibling project:

{
  "dependencies": {
    "rosetta-squint-decode": "file:../rosetta-squint-decode/js/rosetta-squint-decode"
  }
}

Format support

| Format | Status | Backend | |---|---|---| | BMP | byte-exact | hand-written (src/internal/bmp.ts) | | PNG | byte-exact | pngjs | | GIF | byte-exact, first frame only | omggif | | JPEG | byte-exact | @jsquash/jpeg WASM | | WebP | byte-exact | @jsquash/webp WASM | | TIFF | byte-exact, baseline only | utif2 | | HEIC | ±2 px tolerance, single still image | libheif-js WASM |

HEIC caveat: the bundled libheif WASM build diverges from system libheif by ±1–2 per pixel due to differing YCbCr→RGB rounding. The JS port's Group 2 HEIC test uses a max-delta tolerance instead of strict byte-exact. Other ports (Rust, Go, Java, Swift) all link to system libheif 1.17.6 directly and are byte-exact. See DECODER_NOTES.md.

See also

License

BSD-2-Clause.