在枕头中保存GIF动画 [英] Saving an animated GIF in Pillow

查看:88
本文介绍了在枕头中保存GIF动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(Python 3.4,PIL 1.1.7,枕头2.5.1)

(Python 3.4, PIL 1.1.7, Pillow 2.5.1)

我希望这能复制原始GIF.

I expected this to copy the original GIF.

from PIL import Image
im = Image.open(filename)
im.save('temp.gif')

相反,它将第一帧保存为静止图像.

Instead, it saves the first frame as a still.

我在做什么错了?

推荐答案

使用在Github枕头上找到的脚本,

Use the script found on the Pillow Github, here.

 import ImageSequence
 import Image
 import gifmaker
 sequence = []

 im = Image.open(....)

 # im is your original image
 frames = [frame.copy() for frame in ImageSequence.Iterator(im)]

 # write GIF animation
 fp = open("out.gif", "wb")
 gifmaker.makedelta(fp, frames)
 fp.close()

这篇关于在枕头中保存GIF动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆