gifencoder
Streaming server-side animated (and non-animated) gif generation for node.js
Difference from the original
The transparency color will now be forced instead of attempted. This means setting a transparency color of, for example, 0xff0000
will result in exact red as your replacement color. Before this would have resulted in whatever color is closest to red in your frame which could even result in the transparency color being omitted altogether. The library will now also mix the transparency color with the color in the PNG frame when the alpha value is between 1 and 0 to reduce the amount of hard edges you get in the resulting GIF.
Installation
This module is installed via npm:
$ npm install gifencoder
Streaming API - Duplex Piping with Writes
You can also stream writes of pixel data (or canvas contexts) to the encoder:
const GIFEncoder = ;const encoder = 854 480;const pngFileStream = ;const fs = ;const stream =;stream;// Alternately, you can wrap the "finish" event in a Promiseawait {stream;stream;};
NB: The chunks that get emitted by your read stream must either by a 1-dimensional bitmap of RGBA
data (either an array or Buffer), or a canvas 2D context
.
Example: Streaming API - Reads
You can also use a streaming API to receive data:
const GIFEncoder = ;const createCanvas = ;const fs = ;const encoder = 320 240;// stream the results as they are available into myanimated.gifencoder;encoderstart;encoder; // 0 for repeat, -1 for no-repeatencoder; // frame delay in msencoder; // image quality. 10 is default.// use node-canvasconst canvas = ;const ctx = canvas;// red rectanglectxfillStyle = '#ff0000';ctx;encoder;// green rectanglectxfillStyle = '#00ff00';ctx;encoder;// blue rectanglectxfillStyle = '#0000ff';ctx;encoder;encoder;
The above code will generate the following animated GIF:
Contributing
gifencoder is an OPEN Open Source Project. This means that:
Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
See the CONTRIBUTING.md file for more details.
Contributors
gifencoder is only possible due to the excellent work of the following contributors:
Kevin Weiner | kweiner@fmsware.com |
---|---|
Thibault Imbert | http://www.bytearray.org/ |
Eugene Ware | GitHub/eugeneware |
Raine Virta | GitHub/raine |
Paul Ochoa | GitHub/rochoa |
Heikki Pora | GitHub/heikkipora |