JavaScript port of the NeuQuant image quantization algorithm
npm install neuquantA JavaScript port of Anthony Dekker's NeuQuant
image quantization algorithm including a pixel-stream
interface.
npm install neuquant
``javascript
var neuquant = require('neuquant');
// get a palette and indexed pixel data for input RGB image
var res = neuquant.quantize(pixels, quality);
// => { palette:
// streaming interface example
fs.createReadStream('in.jpg')
.pipe(new JPEGDecoder)
.pipe(new neuquant.Stream)
.pipe(new GIFEncoder)
.pipe(fs.createWriteStream('out.gif'));
`
Returns a buffer containing a palette of 256 RGB colors for the input
RGB image. The quality parameter is set to 10 by default, but can
be changed to increase or decrease quality at the expense of performance.
The lower the number, the higher the quality.
Returns a new buffer containing the indexed pixel data for the input
image using the given palette, which is a buffer obtained from the
above method.
Combines the above two methods and returns an object containing both
a palette buffer and the indexed pixel data at once.
As shown in the above example, a streaming API can also be used.
You can pipe data to it, including multi-frame data, and it will
produce an indexed output chunk for each frame. You can access the
palette for each frame by listening for frame` events on the stream.
* The original NeuQuant
algorithm was developed by Anthony Dekker.
* The JavaScript port of NeuQuant was originally done by Johan Nordberg
for GIF.js.
* Streaming interface, wrapper API, and code cleanup by Devon Govett.
MIT