imagemagick animated gif layers showing through transparency

Alec Jacobson

May 01, 2012

weblog/

Today I finally got around to supporting screen dumps from my opengl apps with transparency. I've been wanting to do this for a while, so that I can easily make animated gifs that can be overlaid on a background image/video. I ran into a weird problem using imagemagick's convert tool. I was dumping every frame to a file called: screencapture-01.tga, screencapture-02.tga, ... and then calling:

convert screencapture-*.tga screencapture.gif
 This made an animated gif with transparency, but each frame showed the previous frames behind it. Resulting in something like this: 

worm animation with wrong transparency The magic keyword seems to be "dispose" and calling the following fixed my problem:

convert -dispose 2 screencapture-*.tga screencapture.gif
 which results in: 

worm animation with correct transparency Then I can underlay a background image and get something like: worm animation with correct transparency over clouds Update: To automatically trim the image in the same command use:

convert -dispose 2 screencapture-*.tga -coalesce -repage 0x0 -trim +repage screencapture.gif
convert -dispose 2 screencapture-00*.tga -coalesce -trim -layers TrimBounds screencapture.gif