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.


2 Answers 2


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.

  • 3
    Thanks for your answer. It helped me a lot. I got the best result using gifsicle -i anim.gif --optimize=3 -o anim-opt.gif Nov 21, 2017 at 12:50
  • 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
    Nov 30, 2017 at 18:56
  • Available in FreeBSD ports as well: freshports.org/graphics/gifsicle Sep 16, 2018 at 15:55
  • Could you explain what the -03 means?
    – Sam
    Dec 19, 2019 at 4:41
  • @Jacob "-O[level] - Optimize output GIF animations for space. Level determines how much optimization is done; higher levels take longer, but may have better results. There are currently three levels: […] -O3 - Try several optimization methods (usually slower, sometimes better results)." From the gifsicle man-page
    – Jonta
    Mar 31, 2020 at 13:37

Small addition to @qubodup's answer

Add --lossy flag. This flag varies from 30 to 200, where 30 is good enough.

gifsicle -O3 --colors 256 --lossy=30 -o output.gif input.gif
  • The version of gifsicle that comes with Ubuntu 18.04 does not have the --lossy feature. If I look at the bottom of man gifsicle I see it is version 1.91 from 11 July 2017. The version that comes with Ubuntu 20.04, however, does have the --lossy feature. The bottom of its man page shows it is version 1.92 from 11 July 2017. gifsicle --version on Ubuntu 18.04 shows LCDF Gifsicle 1.91 Copyright (C) 1997-2018 Eddie Kohler. From Ubuntu 20.04 it shows LCDF Gifsicle 1.92 Copyright (C) 1997-2019. Again, version 1.91 does not have the --lossy feature, but version 1.92 does. Jan 11, 2022 at 15:21
  • 1
    The official changelog NEWS.md file here confirms that --lossy was added with Version 1.92. Jan 11, 2022 at 17:32
  • 1
    I ran a bunch of tests, and for my gif, saw no improvement when using -O3 --lossy. Rather than decreasing file size, filze size actually increased by a tiny amount of about 0.3%. Furthermore, the file sizes were exactly identical for me for both -O3 --lossy=30 --colors 16 and -O3 --lossy=100 --colors 16, as well as for -O3 --lossy=30 --colors 256 and -O3 --lossy=100 --colors 256. In other words, whether lossy was set to 30 or 100 seemed to have no difference in my cases whatsoever, for the file I tested at least. Jan 11, 2022 at 17:35
  • 1
    @GabrielStaples That got me puzzled for a while and brought me here. The lossy functionality is not predictable.
    – Omar Abid
    Sep 26, 2023 at 12:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .