社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Matt Bierner kostmo

Matt Bierner kostmo 最近创建的主题
Matt Bierner kostmo 最近回复了
9 年前
回复了 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)
9 年前
回复了 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)