Create and save animated GIF with Python – Pillow
In this article, we are going to use a pillow library to create and save gifs.
GIFs: The Graphics Interchange Format(gif) is a bitmap image format that was developed by a team at the online services provider CompuServe led by American computer scientist Steve Wilhite on 15 June 1987.
A GIF file normally stores a single image, but the format allows multiple images to be stored in one file. The format also has parameters that can be used to sequence the images to display each image for a short time then replace it with the next one. In simple words, GIF is a moving image.
Pillow: Pillow is used for image processing in python. Pillow was developed on top of PIL(python image library). PIL was not supported in python 3, so we use a pillow.
This module is not preloaded with Python. So to install it execute the following command in the command-line:
pip install pillow
Let’s create a gif in step wise:
Step 1: First we import our requirements for PIL module.
Step 2: Create a list after we enter the values of the circle. (0,255,0) it is the color code of green and (255,0,0) is the color code of red.
Step 3: For loop was used to create an animation image.2nd line of code used to set values of the square, that square contains red color and it’s edge size is 200.3rd line used to create square image .4th line used to draw a circle in that square image, that circle color is green.
Step 4: Save the gif image.
Below is the full implementation: