One should always be drunk. That’s all that matters…But with what? With wine, with poetry, or with virtue, as you chose. But get drunk.
― Charles Baudelaire
I find gifs intoxicating, not the looking at them but creating. This is ridiculous. I find sitting down to rip a gif out of a movie and crush it to as small as possible, or to script some sort of weird concoction a lot of fun.
This morning I read Alan’s post: Ooh Ooh Mr Kotter! I Know How To Optimize My GIFs!. It is great, a reminder than some of the fun of giffing is keeping the file size down.
Alan uses photoshop. I’ve never really got a grip of that application. I tend to use firefox, gifsicle or even javascript.
I though that I would se if I could replicate the sort of optimisation he writes about using gifsicle, for a wee bit of fun and learning. I’ve blogged about gifsicle a fair bit here. Gifsicle is a commandline application for working with gifs. It can be downloaded from Gifsicle: Command-Line Animated GIFs.
I stared by a sort of replication Alan’s use of GIPHY’s GIF Maker. I took:
and fed it through the giffy tool.
Like Alan I ended up with a huge gif 4.5MB worth.
So I downloaded it and got some info about it with gifsicle on the commandline:
john$ gifsicle -I drunk.gif * drunk.gif 45 images logical screen 480x270 global color table [256] background 2 loop forever + image #0 480x270 transparent 2 disposal asis delay 0.07s + image #1 480x270 transparent 2 disposal asis delay 0.06s + image #2 480x270 transparent 2 disposal asis delay 0.07s + image #3 480x270 transparent 2 disposal asis delay 0.07s + image #4 480x270 transparent 2 disposal asis delay 0.06s + image #5 480x270 transparent 2
There were a good few more lines, but I got the idea that there were 45 frames, each about 0.07 seconds long.
The plan was to reduce the colours, the number of frames and increase the length of frames to compensate.
The first thing I tried was:
gifsicle -U -O3 -d 28 --colors 128 drunk.gif `seq -f "#%g" 0 4 45` -o drunk-128.gif
What this does
-U: unoptimises the input gif
-O3: optimises the output
-d 28: set the delay to 28/100 sec
- colors 128: cuts down the number of colours
seq -f "#%g" 0 4 45
is a clever bit:-) it produces a sequence of numbers with # in front between 0 & 45 in jumps of four. This causes gifsicle to use those frames of the original gif. We have reduced the number of frames and increased their length to keep the animation the same length.
This resulted in a 1.1MB file, not too good. I repeated the exercise with 64 colors, which got the gif down to 800kb
Not too bad but still a bit big. I then remembered there was a version of gifsicle that could do lossy production of gifs. Alan mentions using this in photoshop. I had downloaded this before but lot it. A qick google found this interesting post: Lossy Optimization for Animated GIFs – Rigor and lead to Lossy GIF compressor where I downloaded the modified version again.
I could now:
gifsicle -O3 --lossy=80 -U -d 28 --colors 128 drunk.gif `seq -f "#%g" 0 4 45` -o drunk-lossy-128.gif
Which give me, a 480k gif:
gifsicle -O3 --lossy=80 -U -d 28 --colors 64 drunk.gif `seq -f "#%g" 0 4 45` -o drunk-lossy-64.gif
reduces the colours and weighs in at 391k (from the original 4.5MB).
I decided to push the lossyness a bit to:
gifsicle -O3 --lossy=160 -U -d 28 --colors 64 drunk.gif `seq -f "#%g" 0 4 45` -o drunk-lossy-160-colors-64.gif
This only shave the gif down to 325K so I think lossy=80 seems a good compromise.
This sort of gif fun might not be everyones drink, but if you are interested, I’ve some more scattered around this blog including: Taking Command of Gifs – 106 drop in and Gifsicle Comparison