Python用图片生成gif

找一组相同大小的图片,几行代码生成gif

import os
from PIL import Image

imgFolderPath = "C:\\Users\\xxx\\Downloads\\imgs"
fileList = os.listdir(imgFolderPath)
# 取第一张图片作为封面
firstImgPath = os.path.join(imgFolderPath, fileList[0])
im = Image.open(firstImgPath)
images = []
for img in fileList[1:]:
    imgPath = os.path.join(imgFolderPath, img)
    images.append(Image.open(imgPath))
# loop为是否循环,duration为gif的每张图片的播放时间
im.save('C:\\Users\\xxx\\Downloads\\imgs\\beauty.gif', save_all=True, append_images=images, loop=0, duration=500)

猜你喜欢

转载自blog.csdn.net/ramblerviper/article/details/119717778