Py学习  »  Python

在Python中将png文件转换为动画gif

Emad Boctor • 4 年前 • 2163 次点击  

编辑:我已经试过PIL了,但似乎没用。有人能用这个结论纠正我吗?或者建议另一个工具包?这个链接似乎支持我关于PIL的结论: http://www.somethinkodd.com/oddthinking/2005/12/06/python-imaging-library-pil-and-animated-gifs/

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53872
 
2163 次点击  
文章 [ 21 ]  |  最新文章 4 年前
Matt Bierner kostmo
Reply   •   1 楼
Matt Bierner kostmo    7 年前

我建议不要使用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)