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 🙏

© 2025 – Pkg Stats / Ryan Hefner

imagequant

v0.1.2

Published

Use imagequant from JavaScript

Downloads

38

Readme

imagequant-wasm

Imagequant bindings for JavaScript

Demo: https://imagequant-wasm.pages.dev

Install

npm i imagequant

Using Vite

Need to install vite-plugin-wasm and set it up according to it's instructions.

Usage

import { ImagequantImage, Imagequant } from "imagequant";

const file = // A file

// Get pixels/imageData of image
const bitmap = await createImageBitmap(file);
const { width, height } = bitmap;

const canvas = new OffscreenCanvas(width, height);
const context = canvas.getContext("2d");
context.drawImage(bitmap, 0, 0, width, height);
const imageData = context.getImageData(0, 0, width, height);

// Need to send data as Uint8Array to Imagequant/WASM
const uint8Array = new Uint8Array(imageData.data.buffer);

const image = new ImagequantImage(uint8Array, width, height, 0);

const instance = new Imagequant();

// Apply options
instance.set_quality(0, 5);

// Do the work
const output = instance.process(image);

const blob = new Blob([output.buffer], { type: "image/png" });

See demo/main.js for example usage.

Options

May seem a bit verbose, but it tries to resemble the Imagequant Rust documentation.

class ImagequantImage {
  constructor(data: Uint8Array, width: number, height: number, gamma: number);
}

class Imagequant {
  /**
   * Make an image from RGBA pixels.
   * Use 0.0 for gamma if the image is sRGB (most images are).
   */
  static new_image(
    data: Uint8Array,
    width: number,
    height: number,
    gamma: number
  ): ImagequantImage;

  /**
   * It's better to use `set_quality()`
   */
  set_max_colors(max_colors: number): void;

  /**
   * Range 0-100, roughly like JPEG.
   *
   * If the minimum quality can't be met, the quantization will be aborted with an error.
   *
   * Default is min 0, max 100, which means best effort, and never aborts the process.
   *
   * If max is less than 100, the library will try to use fewer colors.
   * Images with fewer colors are not always smaller, due to increased dithering it causes.
   */
  set_quality(minimum: number, target: number): void;

  /**
   * 1-10.
   *
   * Faster speeds generate images of lower quality, but may be useful
   * for real-time generation of images.
   *
   * The default is 4.
   */
  set_speed(value: number): void;

  /**
   * Number of least significant bits to ignore.
   *
   * Useful for generating palettes for VGA, 15-bit textures, or other retro platforms.
   */
  set_min_posterization(value: number): void;

  /**
   * Create PNG based on specified settings
   */
  process(image: ImagequantImage): Uint8Array;
}

Build

wasm-pack build --target bundler