私信  •  关注

Matt Bierner kostmo

Matt Bierner kostmo 最近创建的主题
Matt Bierner kostmo 最近回复了
7 年前
回复了 Matt Bierner kostmo 创建的主题 » 在Python中将png文件转换为动画gif

截至2009年6月,最初引用的博客文章有一种方法来创建动画gif in the comments . 下载脚本 images2gif.py (以前 images2gif.py

然后,要反转gif中的帧,例如:

#!/usr/bin/env python

from PIL import Image, ImageSequence
import sys, os
filename = sys.argv[1]
im = Image.open(filename)
original_duration = im.info['duration']
frames = [frame.copy() for frame in ImageSequence.Iterator(im)]    
frames.reverse()

from images2gif import writeGif
writeGif("reverse_" + os.path.basename(filename), frames, duration=original_duration/1000.0, dither=0)
7 年前
回复了 Matt Bierner kostmo 创建的主题 » 在Python中将png文件转换为动画gif

我建议不要使用visvis的images2gif,因为它与PIL/枕头有问题,并且没有得到积极的维护(我应该知道,因为我是作者)。

相反,请使用 imageio

快速肮脏的解决方案:

import imageio
images = []
for filename in filenames:
    images.append(imageio.imread(filename))
imageio.mimsave('/path/to/movie.gif', images)

对于较长的电影,请使用流媒体方法:

import imageio
with imageio.get_writer('/path/to/movie.gif', mode='I') as writer:
    for filename in filenames:
        image = imageio.imread(filename)
        writer.append_data(image)