The gifsicle is a command line tool that can be used to create, edit, optimize, retrieve information, and perform other operations with GIF images.
This tutorial shows how to install gifsicle on Ubuntu 20.04.
Execute the following command to update the package lists:
sudo apt update
Next, install gifsicle:
sudo apt install -y gifsicle
When installation is completed, we can check version of gifsicle:
Download image for testing:
wget -O test.gif https://raw.githubusercontent.com/snipe/animated-gifs/master/hiding/cat-hides-in-couch.gif
gifsicle command allows to specify
-O option to optimize the GIF images. The command supports three optimization levels:
-O3. The higher optimization level is slower but sometimes provides better results. The
-o option allows to provide the output filename.
gifsicle -O3 test.gif -o result.gif
You check the image sizes as follows:
-rw-rw-r-- 1 adminer adminer 971453 Jan 12 03:13 result.gif -rw-rw-r-- 1 adminer adminer 1025400 Jan 12 03:13 test.gif
As we can see, after optimization an image is ~5% smaller than the original image.
The image size can be also minimized by reducing the number of distinct colors. Using
--colors option we can specify the number of colors between 2 and 256.
gifsicle -O3 --colors 128 test.gif -o result.gif
If gifsicle is no longer necessary, it can be removed with command:
sudo apt purge --autoremove -y gifsicle