Skip to content

mbilokonsky/Animated_GIF

 
 

Repository files navigation

Animated_GIF

A Javascript library for creating animated GIFs

How to use it?

Include dist/Animated_GIF.js in your HTML.

var imgs = document.querySelectorAll('img');

// change workerPath to point to where Animated_GIF.worker.js is
var ag = new Animated_GIF({ workerPath: 'dist/Animated_GIF.worker.js' }); 
ag.setSize(320, 240);

for(var i = 0; i < imgs.length; i++) {
    ag.addFrame(imgs[i]);
}

var animatedImage = document.createElement('img');

// This is asynchronous, rendered with WebWorkers
ag.getBase64GIF(function(image) {
    animatedImage.src = image;
    document.body.appendChild(animatedImage);
});

If you instance lots of Animated_GIF objects, it's strongly recommended that you call their destroy method once you're done rendering the GIFs, as browsers don't seem to be happy otherwise. See the stress test for an example of this in use!

Minified versions

You can also use the minified versions in dist/: dist/Animated_GIF.min.js. Remember to set the worker path to dist/Animated_GIF.worker.min.js!

Available options

These are set when creating an Animated_GIF instance:

  • sampleInterval: how many pixels to skip when creating the palette. Default is 10. Less is better, but slower.
  • numWorkers: how many workers to use. Default is 2.
  • workerPath: path to the Animated_GIF.worker.js file (or Animated_GIF.worker.min.js). Default is dist/Animated_GIF.worker.js, change accordingly if you place the files somewhere else than dist.

Tests and examples

Check the tests_* files:

See it in action

Some sites and apps using it:

Credits

  • Anthony Dekker's NeuQuant image quantization algorithm which was ported from C into Java by Kevin Weiner and then to ActionScript 3 by Thibault Imbert, and to JavaScript by antimatter15, and fixed, patched and revised by sole.
  • Dean McNamee's omggif library - for actually encoding into GIF89

About

Javascript library for creating animated GIFs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published