图片文件夹路径为:D:\Pycharm\PRO_Anaconda\Class4_2\test
import imageio
import os
work_path = os.getcwd() # 获得当前工作目录路径
Photo_path = work_path + "/test" #照片文件路径
filenames = []
for files in os.listdir(Photo_path):
if files.endswith("jpg") or files.endswith("jpeg") or files.endswith("png"):
file = os.path.join(Photo_path, files) # 路径拼接
filenames.append(file)
images = []
for filename in filenames:
images.append(imageio.imread(filename))
imageio.mimsave("My.gif", images, duration=0.5) # 0.5s一帧
说明:
scipy版本 > 1.2.0:
命令: scipy.misc.imread() ==> imageio.imread()