码迷,mamicode.com
首页 > 编程语言 > 详细

python imageio 图片生成gif

时间:2018-07-21 16:59:40      阅读:2013      评论:0      收藏:0      [点我收藏+]

标签:bubuko   dir   filename   2.7   The   alt   main   pen   lis   

#!/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 )

 

 

 

 

技术分享图片

技术分享图片

python imageio 图片生成gif

标签:bubuko   dir   filename   2.7   The   alt   main   pen   lis   

原文地址:https://www.cnblogs.com/zealousness/p/9346339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!