Write in front
I have shared with you how to python
combine multiple pictures into a gif animation (click here to view). But what if the synthesized animation is too big, how to compress it?
Dependent modules
pip install pygifsicle
Sample code
from pygifsicle import optimize
optimize('test.gif', "optimized.gif") # For creating a new one
Parameter Description
test.gif
: This is the gif
name of the file to be compressed
optimized.gif
: this is the name of the compressed gif
file
Precautions
Compression requires gifsicle.exe
program support, and different systems have different solutions.
MacOS
When the pip install pygifsicle
command is executed , the Brew
installation will be used automatically gifsicle
, so no action is required.
Linux
Please use the sudo apt-get install gifsicle
command to install gifsicle
.
Windows
Download the gifsicle
program yourself, click here to download. After downloading, gifsicle.exe
put .py
it under the same level file.
Test Results
Before compression: 44.5KB | After compression: 6.47KB |
---|---|
Tips
No, python
it doesn't matter, we have directly packaged a GIF compression software here, you can use it directly, click here to download.