在Python中生成动画GIF [英] Generating an animated GIF in Python

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

问题描述

我正在尝试使用images2gif.py(粘贴到最新版本的粘贴框:bit.ly/XMMn5h)生成动画GIF.

I'm trying to generate an animated GIF using images2gif.py (pastebin to the most recent verson : bit.ly/XMMn5h ).

我正在使用以下Python脚本:

I'm using this Python script:

__author__ = 'Robert'
from images2gif import writeGif
from PIL import Image
import os

file_names = sorted((fn for fn in os.listdir('.') if fn.endswith('.gif')))
#['animationframa.png', 'animationframb.png', ...] "

images = [Image.open(fn) for fn in file_names]

size = (150,150)
for im in images:
    im.thumbnail(size, Image.ANTIALIAS)

print writeGif.__doc__

filename = "my_gif.GIF"
writeGif(filename, images, duration=0.2)

但是,出现以下错误:

File "C:\Python27\lib\images2gif.py" , line 418, in writeGifToFile
globalPalette = palettes[ occur.index(max(occur)) ] ValueError: max() 
arg is an empty sequence

在我看来发生的事情是空的.有什么问题,有更好的方法吗?

It seems to me that occur is empty. What is wrong, and is there a better way?

推荐答案

好,我已经在两台不同的机器上测试了您的确切代码,并且在两台机器上都可以正常工作.一台计算机是Ubuntu 12.04,另一台正在运行Windows XP.他们俩都使用Python 2.7和最新版本的images2gif,其中我从这里下载.我建议以下内容:

OK I have tested your exact code on two different machines, and it works perfectly on both. One machine is Ubuntu 12.04 and the other is running Windows XP. They are both using Python 2.7, and the latest version of images2gif which I downloaded from here. I recommend the following:

  1. 检查您使用的是哪个版本的python和库,尝试获取最新版本.
  2. 在另一台机器上测试
  3. 尝试并卸载python和所有库,然后尝试重新安装

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

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