python imageio 图片生成gif
2018-07-21 13:13 ZealouSnesS 阅读(3203) 评论(0) 编辑 收藏 举报#!/bin/python3 import matplotlib.pyplot as plt import imageio,os TIME_GAP=0.075 #两帧之间的时间间隔,秒为单位 FILE_PATH="./testwalk/" BEGIN_INDEX=1 END_INDEX=7 FORMAT=".jpg" # 返回gif def create_gif(image_list, gif_name): print(image_list) frames = [] for image_name in image_list: frames.append(imageio.imread(image_name)) # Save them as frames into a gif imageio.mimsave(gif_name, frames, 'GIF', duration = TIME_GAP) return # 返回图片路径名的list def filenames_gen(): filenames = [] filenames.append(FILE_PATH+"-2.77555756156e-17.jpg") # filenames=(fn for fn in os.listdir('./testwalk') if fn.endswith(FORMAT)) # filenames=[fn for fn in os.listdir('./testwalk') if fn.endswith(FORMAT)] for i in range(BEGIN_INDEX,END_INDEX+1): filenames.append(FILE_PATH+str(i/10)+FORMAT) filenames.append(FILE_PATH+str(-i/10)+FORMAT) filenames.reverse() print(filenames) return filenames if __name__ == '__main__': create_gif(filenames_gen(),'created_gif.gif' )