找一组相同大小的图片,几行代码生成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)
本文介绍如何利用Python的PIL库,通过几行代码实现从一组相同大小的图片中创建动态GIF,适合初学者快速上手。
2228

被折叠的 条评论
为什么被折叠?



