我正在尝试使用 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 .我推荐以下内容:
- 检查您使用的 python 和库的版本,尝试获取最新版本。
- 在另一台机器上测试
- 尝试卸载 python 和所有库,然后尝试重新安装
关于python - 在 Python 中生成动画 GIF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13041893/