python - 在 Python 中生成动画 GIF

标签 python gif animated-gif

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

我正在使用这个 Python 脚本:

__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

在我看来 occur 是空的。哪里出了问题,有没有更好的办法?

最佳答案

好的,我已经在两台不同的机器上测试了您的确切代码,它在两台机器上都运行良好。一台机器是 Ubuntu 12.04,另一台运行 Windows XP。他们都使用 Python 2.7 和最新版本的 images2gif I downloaded from here .我推荐以下内容:

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

关于python - 在 Python 中生成动画 GIF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13041893/

相关文章:

html - html中的<img>标签是否支持gif动画?

python - 使用 openshift 部署本地 django 应用程序

python - 在 python 中添加额外的列以输出 csv 文件

python - 检查下一个值是否等于python循环中的当前值?

javascript - 页面加载动画方法

c# - 显示 .gif 并在访问服务器期间继续播放 - asp .net

python - 将 Excel 文件流保存到 azure blob 存储

javascript - 鼠标离开后强制 gif 重新加载

java - 如何计算GIF图像的大小?

java - 我可以向 JButton 添加动画 gif 文件吗?