Optimize animated GIF size in command-line

29

6

How to compress GIF animations? For example by reducing the color index.

The files are generated using Imagemagick but optimization seems complicated.

For example, the following animation is 864KB at 150x119:

example animation

To be used on a Linux machine.

qubodup

Posted 2016-07-31T23:47:20.553

Reputation: 3 736

See also Is there something like pngcrush for GIFs? on Stack Overflow for more answers.

– user – 2019-05-06T09:36:32.990

Answers

43

Use gifsicle (available for Mac OS X, Windows, DOS, Debian, FreeBSD and NetBSD).

gifsicle -i anim.gif -O3 --colors 256 -o anim-opt.gif

This will optimize and reduce to 256 colors, if the animation uses more colors (the example image does).

You can reduce the size by reducing the number of colors:

example image with only 256 colors 512KB, 256 colors

example image with only 128 colors 412KB, 128 colors

example image with only 64 colors 340KB, 64 colors

example image with only 32 colors 240KB, 32 colors

example image with only 16 colors 140KB, 16 colors

Based on another Q&A.

qubodup

Posted 2016-07-31T23:47:20.553

Reputation: 3 736

1Thanks for your answer. It helped me a lot. I got the best result using gifsicle -i anim.gif --optimize=3 -o anim-opt.gif – Mostafa Ahangarha – 2017-11-21T12:50:30.320

works great! for some odd reason, im using a shell script that uses imagemagick and oddly it isnt working with gifs we got from videos via final cut pro (exported as image sequence) then exported thru photoshop but otherwise works on other gifs. – SMT – 2017-11-30T18:56:15.830

Available in FreeBSD ports as well: https://www.freshports.org/graphics/gifsicle/

– Mateusz Piotrowski – 2018-09-16T15:55:38.603

Could you explain what the -03 means? – Jacob – 2019-12-19T04:41:42.217