Python | 图片序列生成 gif

'''
通过文件夹下的图片序列生成 gif 图
'''
__author__  = '-T.K.-'
__license__ = 'MIT'
__date__    = '2018-12-01'

import os

import imageio

folder_name = 'images'

def create_gif(image_list, gif_name):
    frames = []
    for image_name in image_list:
        frames.append(imageio.imread(os.path.join(folder_name,image_name)))
    # Save images as frames into a gif 
    imageio.mimsave(gif_name, frames, 'GIF', duration = 0.1)
    return
 
def main():
    image_list = list(os.walk(folder_name))[0][-1]
    gif_name = 'generated_gif.gif'
    create_gif(image_list, gif_name)

if __name__ == '__main__':
    main()

你可能感兴趣的:(Python | 图片序列生成 gif)