这是一个将图片生成gif动画的最简单程序。程序很简单,但是安装PIL和images2gif 的时候遇到不少坑。
使用Pycharm作为编辑器,不管是使用Python 2.7还是3.4时,PIL库都加载不了。使用3.4把pillow库加载上了,images2gif库却又不支持3.X。幸好找到一个替代版本,直接把images2gif.py给替换了,终于可以用了。
#coding=utf-8
#for Python3,
# 1. After installing images2gif, use https://github.com/isaacgerg/images2gif instead of installed one
# 2. Install pillow instead of PIL
from PIL import Image
from images2gif import writeGif
filenames = ['1.png', '2.png', '3.png', '4.png', '5.png', '6.png', '7.png', '8.png', '9.png', '10.png' ]
images = [Image.open(fn) for fn in filenames]
outfilename = "animation.gif"
writeGif(outfilename, images, duration=0.5, subRectangles=False)