【 Fan benefits 】 Official account , Get a full set of videos , Using third party libraries pillow、 Add existing pictures , adopt python Automatic synthesis gif Moving graph , I like to make it up ' Focus on ' Well !
Install dependency library
pip install Pillow
Import dependency package
''' Import dependency package '''
# System operation Library
import os
# Image processing library
from PIL import Image
Generate dynamic pictures
# Initialize the picture address folder path
image_path = '/usr/load/picture'
# Get file list
files = os.listdir(image_path)
# Define the global path of the first file
file_first_path = os.path.join(image_path, files[0])
# obtain Image object
img = Image.open(file_first_path)
# Initialize the file object array
images = []
for image in files[1:]:
# Get the full path of the current picture
img_path = os.path.join(image_path, image)
# Use current picture Image Object open 、 Then join in images Array
images.append(Image.open(img_path))
# Save and generate gif Moving graph
img.save('beauty.gif', save_all=True, append_images=images, loop=0, duration=2000)