Various .gif optimization methods vs. file size

I have captured my cool spinner as a .gif animation. It has 241 frames, last 8 seconds and has 3.59 MB (3 768 320 bytes) size.

Quite huge, to be honest, so I decided to play a little bit with fabulous ezgif.com’s Animated GIF optimizer and compressor tool to see, if I can get down a little bit with it.

BTW: Consider taking a headache pills before pressing the button below! :) You’re going to see a really huge number of spinning gear wheels in this article. Believe me or not, you can get really, really wako out of watching them… spinning around… spinning around… spinning… around… around… arrrr! :)

The original file is:

And here are all the tests that I have performed.

Color reduction

First two optimizers tested by me are based on colors that your original file has.

Single color table

First one is based on introducing single color set for each frame instead of separate ones.

In my case this has reduced the original file size to 2.83 MB (2 977 792 bytes), so 21%.

Color reduction to 16 colors

The original image has 255 unique colors. Reducing this to 16 colors gave me 2.64 MB (2 768 896 bytes), so 21.5% of the original and the following visual effect:

LZW compress

This algorithm can be applied to each frame to reduce entire file size. You can pick a compression level between 5 and 200, where 30 is very light compression, and 200 is very heavy one.

I bit odd (I’d expect 0-100 compression level), but… well, that’s not my problem.

77 compression level

Here we have 2.57 MB (2 703 360 bytes) resulting file size (28.5%) and…

111 compression level

Increasing compression to 111 level gives us 2.51 MB (2 641 920 bytes) — ~30% reduction — and this:

Transparency optimization

This filter or optimizer reduces amount of data for transparency stored in your file. Please, note that I was getting some results even though my base file does not use transparency at all.

3% Fuzz

Well… I don’t know how 3% fuzz should work or what is an expected outcome, but from my example (base) image this filter has produced a 4.28 MB (4 489 216 bytes) file, so I have received a… 119% “optimization” :)

7% Fuzz

This level of transparency optimization produced file of 3.26 MB (3 428 352 bytes) in size, so 10% optimization (or 90% of original size).

But, if you take a close look, you can already clearly see animation distortions or color smudges. So, generally speaking overall image quality reduction can be easily observed:

11% Fuzz

I have been working with smaller image sized than browser actually shows (enlarged). I haven’t noticed above distortions and when with testing transparency reduction optimization with 11% fuzz.

The resulting image is 2.91 MB (3 051 520 bytes). We are getting next nearly 10% file side reduction, but the corresponding image quality reduction is even clearer:

So this kind of optimization can be used only for images:

  • Much smaller in width and height
  • Having much less frames or much longer lasting frames
  • Having darker background or being generally darker than my examples

Again, you have to test on your own image to see, if you can proceed with such fuzz.

33% Fuzz

With the above knowledge, I tried 33% fuzz just for fun. File has 1.96 MB (2 060 288 bytes) size around half of the original, but the visual effects are… well…

Remove frames

You can remove unwanted or unnecessary frames, either manually or automatically. And this of course does corresponds to file size reduction.

Based on what picture or animation your .gif file actually depict, you will end up with a variety of results — from a change not noticeable by viewers to complete destruction of the animation.

Remove every second frame

This is how my base animation looks when I get rid of every second frame, so reduce total number of animation frames by half:

Animation speed is also increased by 50%, but overall image and animation quality seems not affected. File size is 1.70 MB (1 785 856 bytes), so we have (as we could expect) around 50% of file size reduction.

Remove every third frame

If the speed is too fast or you see some graphical glitches, you can consider reducing 33% of frames:

File size is 2.26 MB (2 375 680 bytes) in this case, so 63% of the base file. That looks promising.

Remove every fourth frame

Finally, ezgif.com’s Animated GIF optimizer and compressor allows you to drop of 25% of frames:

The resulting file has 2.54 MB (2 670 592 bytes), so the reduction is exactly 30%.

Remove duplicate frames

This is the last option that I have tried, but since my base image does not include any (or includes just a couple) duplicated frames so the result in my case was insignificant (a couple of kilobytes difference).

Leave a Reply