Image-Q is a comprehensive TypeScript library for image color quantization, providing various algorithms to reduce the number of colors in an image while preserving visual quality. It supports alpha channels and offers multiple quantization methods, including NeuQuant, RGBQuant, and Xiaolin Wu's algorithms, alongside a broad selection of color distance formulas such as Euclidean, Manhattan, CIEDE2000, and CIE94. The library features both synchronous and promise-based asynchronous APIs, as well as generator-based advanced APIs, making it adaptable for various use cases. It supports both browser (Chrome 7+, Firefox 4+, IE 10+, Opera 11.6+, Safari 5.1+) and Node.js (6.0+) environments. Currently stable at version 4.0.0, the package has a moderate release cadence, with previous major versions introducing significant API changes, particularly around method naming and build outputs. Its key differentiators include a rich set of algorithms and distance metrics, full TypeScript support, and broad platform compatibility. The library is MIT licensed.
npm install image-qVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to perform image quantization using a mock `ImageData` object, applying a NeuQuant palette generation algorithm and Floyd-Steinberg dithering to reduce the image's color count. It showcases the full async API flow.
Update calls from `quantize()` to `quantizeSync()` for synchronous operations, or use the new `await quantize()` for asynchronous, promise-based workflows.
Review and update usages of affected color distance classes to their new names according to the API documentation.
Users relying on strict CommonJS module behavior or specific CJS build characteristics should verify compatibility. Consider using ES module imports (`import * as iq from 'image-q';`) with a bundler for optimal results, especially in Node.js ESM projects.
If you intend a synchronous operation, change the call to `paletteQuantizer.quantizeSync(...)`. If you intend an asynchronous operation, ensure you `await` the call: `await paletteQuantizer.quantize(...)`.
Use the ES Module import syntax: `import * as iq from 'image-q';` or `import { utils } from 'image-q';`. Ensure your environment or bundler is configured to handle ES Modules.Ensure you are using specific named imports for sub-modules if you're not importing the entire namespace: `import { utils, dist, palette, image } from 'image-q';` rather than relying solely on `import * as iq from 'image-q'` for direct access to sub-modules without namespace qualification (e.g., `iq.utils.PointContainer`).No dependency data recorded yet.