gif-stream
A streaming GIF encoder and decoder for Node and the browser
Installation
npm install gif-stream
For the browser, you can build using Browserify.
Decoding Example
This example uses the concat-frames module to collect the output of the GIF decoder into an array of frame objects.
var GIFDecoder = ;var concat = ; // decode a GIF file to RGB pixelsfs ;
Encoding Example
You can encode a GIF by writing or piping indexed/quantized data to a GIFEncoder
stream.
If you write data to it manually, you need to first quantize the pixel data to produce a
color palette and a buffer of indexed pixels. You can use the neuquant
module to do this.
Alternatively, if you have a stream of RGB data already, you can pipe it first to a neuquant stream, and then to a GIF encoder, which will do the hard work of quantizing and writing indexed data for you.
var GIFEncoder = ;var neuquant = ; // encode an animated GIF file by writing pixels to it.// you need to manually quantize the data to produce a palette and indexed pixels.var q = neuquant; var enc = width height palette: qpalette ;enc; // write indexed dataenc; // or, pipe data from another RGB stream// boom: streaming image transcoding!fs ; // maybe you want to preserve the original palette and indexing?// you can do that too!fs ;// somewhat useless example, but this may be useful for instance// if you are breaking an animated GIF into multiple static GIFs
License
MIT