This is the 11th day of my participation in Gwen Challenge
In Python, you can convert multiple images into giFs. You can also extract the image from a GIF
Before we get started, let’s start with a GIF (preview)
01, Picture to GIF
1. Preparation
Before you start merging, figure out which images to convert and install the corresponding Python libraries
Here, I found 9 images on the Internet and stored them in the IMG folder. These 9 images will be converted into GIFs later.
pip install imageio
Copy the code
Install the Imageio library, which converts multiple images to GIFs, using the command above.
Import the appropriate libraries
import imageio
import os
import os.path as osp
Copy the code
2. The conversion
Read all the images in the IMG folder and read the image contents through imageio.
Convert and save as chenge.gif
Where duration = 1 / FPS, that is, the larger duration is, the slower the GIF changes. The current duration is 0.1, and the result is as follows:
The current duration is 0.5, which results in the following:
02, GIF extract pictures
1. Preparation
The import library of PIL
from PIL import Image
Copy the code
GIF to extract (cheneng.gif saved above is used here)
Extracted 2.
Here we extract the image from chenge.gif, save it to gif-to-pic folder and name it from 0.jpg
You can see that the image in the GIF has been extracted successfully.
03, subtotal
This article explains how to convert multiple images into GIFs and how to extract the image from a GIF. In order to facilitate everyone to practice, Chen Elder brother has modular code.
For the convenience of learning, Brother Chen has uploaded the complete source code of this article and corresponding pictures and GIfs, which need to be obtained from the public: GIFpic
Finally, don’t understand the place can leave a message below, communicate together.