current position:Home>Python image processing, automatic generation of GIF dynamic pictures

Python image processing, automatic generation of GIF dynamic pictures

2021-08-23 20:16:32 Python concentration camp

【 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 !

 Insert picture description here

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)

 Insert picture description here

copyright notice
author[Python concentration camp],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2021/08/20210823201629389r.html

Random recommended