I wrote a new program called flexiGIF:
- reduce the filesize of GIFs
- generate GIFs that can be loaded by any GIF decoder; stay fully compatible to this three decades old file format
- perform lossless compression, that means the result is 100% pixel-wise identical to the original file
- support animated GIFs, too
- sacrify tons of CPU cycles ... flexiGIF is multitudes slower than your typical GIF encoder; it often takes a few minutes to optimize a single file
On average I can shrink GIFs by about 1 to 2%.
The program Gifsicle (https://www.lcdf.org/gifsicle/) is almost always recommended as the best GIF optimizer available. flexiGIF beats it consistently.
Basically I combine two algorithms (invented by others):
- flexible positioning of the Clear Code (which resets the LZW dictionary)
- one-step-lookahead instead of greedy match finding
These two algorithms purely optimize the LZW data inside a GIF file. Everything else is kept unchanged - palette, comments, etc. remains exactly as before.
Some examples (originally from the English Wikipedia / GIF file format: https://en.wikipedia.org/wiki/GIF , the displayed GIFs are the optimized ones):
flexiGIF
55,866 bytes
gifsicle 1.91
56,739 bytes
original
56,752 bytes
flexiGIF 2018.09a (run after Gifsicle)
339,613 bytes
gifsicle 1.91
347,919 bytes
flexiGIF 2018.09a
352,615 bytes
(original)
363,021 bytes
A few hours ago I finished my 4th Berlin Marathon (inline skating) so here is a bonus picture I took in front of the German parliament (close to start/finish line):
flexiGIF 2018.09a
167,483 bytes
gifsicle 1.91
170,958 bytes
Irfanview 4.51
171,064 bytes
You can find more details on my website https://create.stephan-brumme.com/fl...-optimization/
The source code will be published soon (probably by the end of September 2018 ); it still needs some polishing.
Please no discussion about pro and cons of the GIF file format ... but if you could recommend more LZW tricks: I'm always open for new ideas !