Skip to content


Subversion checkout URL

You can clone with
Download ZIP
openframeworks addon to export animated gifs
C++ Objective-C
Latest commit afe04af @jesusgollonet Add MIT License
Failed to load latest commit information.
example Revert example to original
output Add 2 output examples
src Add nColors back
.gitignore Add .gitignore
LICENSE Add MIT License Add MIT License


Export animated gifs from openframeworks.

Shameless plug

Tested with openframeworks 0.8.1 osx.


There is a simple example included

create an instance of ofxGifEncoder

ofxGifEncoder gifEncoder;

call setup

gifEncoder.setup(frameW, frameH, frameDuration, nColors);

(frameDuration is a float in seconds and nColors is an int from 0 to 256.)

optionally :) (see dithering patterns on the h file)


then add frames, either as ofImages or unsigned char *

gifEncoder.addFrame(foo.getPixels(), frameW, frameH);

when you're ready to save"test.gif");

If you want to do something when saving is finished, you can subscribe to the event OFX_GIF_SAVE_FINISHED *

ofAddListener(ofxGifEncoder::OFX_GIF_SAVE_FINISHED, this, &testApp::onGifSaved);
onGifSaved(string & fileName)


threaded saving, events, error checking and frame managing adapted from Nick Hardeman.


  • (x) Transaparent gifs (currently testing)
  • Provide option to choose palette
  • proper frame compression



Experimental transparency support has been added. However, I haven't found a nice way to gracefully convert from a 32bit alpha image to an 8bit alpha image with Freeimage (openframeworks image library).

The process I'm following is sort of a green screen (check ofxGifEncoder::convertTo24BitsWithGreenScreen):

  • substitute the values in the alpha channel of the 32bit transparent image by a predefined color (ofColor(0,255,0) -> bright green)
  • convert to 24bit
  • convert to 8 bit using FreeImage_ColorQuantize, which takes care of palettizing the image (and therefore choosing the final colors)
  • find in the palette the color closest to our predefined color, and set that as transparent.

At the moment there are 2 flaws with transparency:

  • If there is a color in your image which it's closest to the palettized green screen color, that one will be picked for alpha. You'll probably see big green areas in your exported gif.
  • Images with alpha gradients will have green added on the semi transparent parts.

I'm thinking of fixes for both.

Gif size

one thing that it's not quite there yet is appropiate gif compression, so if your images are big or you have many frames you may end up with unnecesarily fat gifs.

If you use it, I'd love to see what for. Let me know:

Shameless plug


This addon is distributed under the MIT License which means you can use it in any context: commercial or non-commercial, public or private, open or closed source.

Something went wrong with that request. Please try again.