I've written a lot about converting different media types lately, especially GIFs, including Convert Video to GIF or GIF to Video, Detect if a GIF is Animated, and Get the First Frame of an Animated GIF with ImageMagick, but whether it's ImageMagick or ffmpeg doing the work, GIFs do not always come out optimized. Since GIFs can be taxing on the user's machine, it's best to optimize GIFs for top performance. Another handy GIF manipulation library, gifsicle, has a few built in methods for optimizing GIFs.
Before jumping into the GIF optimization commands, it's important to point out that gifsicle is much more than a GIF optimizer. gifsicle can resize GIFs, merge GIFs, and do just about anything you'd hope you could do with a GIF.
gifsicle has three types of GIF optimization to choose from:
-O1
Stores only the changed portion of each image. This is the default.-O2
Also uses transparency to shrink the file further.-O3
Try several optimization methods (usually slower, sometimes better results).
The shell command to optimize GIFs is:
If you have the time and patience, I recommend -O3
as was able to get much more optimized GIFs with this method. On some GIFs I saved up to 20% in file size, and depending on your specific GIF, you may be able to save more!
Gifsicle (an acronym of the gif and popsicle words) is an open source, free and powerful command-line software that can be used to easily and quickly create, edit, manipulate and collect.
Released:
Python package wrapping the gifsicle library for editing and optimizing gifs.
- Is a programming language that lets you work quickly and integrate systems more effectively.
- Winamp 2.9 reimplemented in HTML5 and JavaScript.
Project description
Python package wrapping the gifsicle library for editing and optimizing gifs.
How do I install this package?
As usual, just download it using pip:
While running the installation, on MacOS the setup will automatically install gifsicle using Brew.
On Linux you will need to install gifsicle using apt-get as follows:
On Windows you will need to download and install the correct port of the library for your OS.
Tests Coverage
Since some software handling coverages sometime get slightly different results, here’s three of them:
Usage examples
The library is currently pretty plain: it offers a wrapper to gifsicle and a method to optimize gifs, wrapping the options for gifsicle.
Optimizing a gif
To optimize a gif, use the following:
General wrapper
To run gifsicle from Python use the following:
Learn more about the general wrapper by reading the function documentation.
Troubleshooting
One of the most common issues you can get, especially on windows, is that simply the gifsicle library is not available system wide. Do try to run gifsicle in your terminal to check if the library is properly installed.
Help and support
Wanna add another wrapper for easier usage? Do a pull request!
Did you find an error or weird behavior? Open an issue!
Gifsicle
Release historyRelease notifications | RSS feed
1.0.2
1.0.1
1.0.0
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size pygifsicle-1.0.2.tar.gz (5.0 kB) | File type Source | Python version None | Upload date | Hashes |
Hashes for pygifsicle-1.0.2.tar.gz
Free Animated Gifs
Algorithm | Hash digest |
---|---|
SHA256 | e33aacf8ec0f6231a8b3527484f3b50a77c7a7aeac26af53ade32e4d39d6eb50 |
MD5 | 993e338a39b11e67e2cbd6bff676c67c |
BLAKE2-256 | 09237adf797d3a65f568bb96e85b1a7ad046cc9b78be627df75927b83d6d6323 |