Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Compressing an animated GIF with gifsicle or ImageMagick mogrify#
Using gifsicle#
Tip via Mark Norman Francis on Twitter:
Saw your GIF size TIL, and
gifsicle -O3 --colors 48 --lossygets it down to 320k. You can tweak the number of colours and loss to get it smaller but that’s when it starts to look worse to my eyes
I installed it using brew install gifsicle and ran it like this:
1/tmp % ls -lah datasette-launch.gif2-rw-r--r--@ 1 simon wheel 3.7M Sep 13 12:52 datasette-launch.gif3/tmp % gifsicle -O3 --colors 48 --lossy -o datasette-launch-smaller.gif datasette-launch.gif4/tmp % ls -lah datasette-launch*5-rw-r--r-- 1 simon wheel 613K Sep 13 12:54 datasette-launch-smaller.gif6-rw-r--r--@ 1 simon wheel 3.7M Sep 13 12:52 datasette-launch.gifOriginal: 3.7MB file:

Compressed 613KB file:

The reduced colours there were a bit too much for me, especially for the purple gradient buttons at the end. So I tried this instead:
1gifsicle -O3 --colors 128 --lossy -o datasette-launch-smaller-2.gif datasette-launch.gifWhich gave me a 723KB file which I think looks good enough for my purposes:

Using ImageMagick mogrify#
Found this tip on Stack Overflow: to reduce the site of an animated GIF, you can use the mogrify tool like this:
1mogrify -layers 'optimize' -fuzz 7% sqlite-convert-demo.gifThis saves over the original, so make a copy of it first.
I ran this against this 1.3MB animated GIF:

The result was this 401KB GIF:

The -fuzz 7% option is documented here - it treats similar colours as the same colour:
The distance can be in absolute intensity units or, by appending % as a percentage of the maximum possible intensity (255, 65535, or 4294967295).