【粉丝福利】关注公众号,获取全套视频资料,使用第三方库pillow、将现有的图片,通过python自动合成gif动图,喜欢小编点个 ‘关注’ 吧!
安装依赖库
pip install Pillow
导入依赖包
'''导入依赖包'''
import os
from PIL import Image
生成动态图片
image_path = '/usr/load/picture'
files = os.listdir(image_path)
file_first_path = os.path.join(image_path, files[0])
img = Image.open(file_first_path)
images = []
for image in files[1:]:
img_path = os.path.join(image_path, image)
images.append(Image.open(img_path))
img.save('beauty.gif', save_all=True, append_images=images, loop=0, duration=2000)
|