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

查看:42
本文介绍了在 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)

但是,我收到以下错误:

However, I am getting the following error:

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天全站免登陆