I wanted to make a gif picture a few days ago. I searched the Internet for a while but didn’t find a suitable gif production software. Finally, I asked the students in the group to recommend a gif software called gifCam. It was good to use, only a few The size of a hundred K, I think I can also make a gif maker, so today is mainly for this matter.
Not much nonsense, I went directly to the technical stage. I found a graphics library called Pillow through searching in python. After researching it, I found that it can solve my own problem.
My requirement is to be able to record gif pictures, because it is the first time to do this kind of thing, so I need to break down the requirements.
Step 1: I need to be able to record the screen, that is, the screen capture function, save the current screen, the technical plan is temporarily undecided, postponed!
Step 2: I need to be able to merge the screenshots and synthesize gif images. I have found a suitable library and do it immediately.
Step 3: Make the python file a friendly interface, non-core functions, postpone.
The core function of the whole is to synthesize pictures, so what I have to do today is to find some pictures to synthesize into gif
The environment on my machine is python3.8
The required package is Pillow. Note that it needs to match your python version. It is recommended to use the following method to install
Enter the following command at the console:
pip install Pillow
# coding:utf-8 import os from PIL import Image imgFolderPath = "E:\\child\\bug\\WxBot\\xin\\beauty" fileList = os.listdir(imgFolderPath) firstImgPath = os.path.join(imgFolderPath, fileList) im = Image.open(firstImgPath) images =  for img in fileList[1:]: imgPath = os.path.join(imgFolderPath, img) images.append(Image.open(imgPath)) im.save('beauty.gif', save_all=True,append_images =images,loop = 0,duration=2000)
imgFolderPath: is the folder where the picture is located
os.listdir(imgFolderPath)lists all file names and returns the list
firstImgPath = os.path.join(imgFolderPath, fileList)The absolute address of the first image to be spliced
im = Image.open(firstImgPath)takes the first file as the first frame
for img in fileList[1:]: traverse all the remaining pictures, read and add to the images list
im.save('beauty.gif', save_all=True,append_images =images,duration=2000)The core function of the current function
beauty.gifis the full name of the gif file to be saved
save_allsave all images
duration=2000Play each frame of picture for 2000 milliseconds
loop = 0GIF pictures keep looping repeatedly (loop=0, if set to 1, then loop once, set to 2, loop twice, and so on)