Monday, February 8, 2010

How to make an animated gif with small file-size


I wanted to make an animation showing the evolution of global temperature and the number of sunspots over the last 129 years. I used gnuplot to spit out 129 png files (each of size 2k to 14k), then the question was how to make the animation.
Initially I tried:
convert -delay 10 -loop 0 *.png -delay 1000 2009.png Anim.gif
which made a grand-looking animated gif, but its size was enormous - over 1 megabyte! Many thanks to Patrick Welche for telling me to try the deconstruct flag:
convert -delay 10 *.png -deconstruct Anim.gif
which makes a 161k animation.
Here is a link to the resulting animated gif (161k)

6 comments:

Iain Murray said...

I use gifsicle to make animated gifs (Debian/Ubuntu package available).

Normally you optimize an animated gif with: gifsicle -b -O2 file.gif

In this case the complicated file that resulted from both -deconstruct and gifsicle confused firefox (although chrome and opera worked). So I had to first make the file simpler and then reoptimize.

gifsicle --colors=255 -b Anim.gif ; gifsicle --unoptimize -b Anim.gif ; gifsicle -b -O2 Anim.gif

The resulting file still works well and is only 45k.

PS for other image filetypes check out jpegoptim and optipng.

Iain Murray said...

Update: the file from gifsicle works better in firefox (as well as being >3x smaller).

If I view your link above, bring another browser window in front and swap back, I see white blocks occluding the image. Pressing the back and forward buttons in firefox also causes this problem.

The gifsicle image works robustly as far as I can tell.

David MacKay FRS said...

Thanks Iain! I have re-made the gif using these commands, and it's now even smaller.

gifsicle --delay 10 --loop=3 gif/*.gif --delay 1000 gif/2009.png.gif > ../Anim.gif ;
gifsicle -b -O2 ../Anim.gif

Unknown said...

thank you for sharing.


Melbourne SEO Services

Fonts World said...

I really like your work man. So if you want to transfer gif file to other format then use this tool;

Files Converter Online

Fonts World said...

That can transfer your gif file to other formats;

Swf to Mov

Gif to Mov

Wmv to Gif

Mp4 to Mkv

3gp to Mp3

Tga to Jpg