【发布时间】:2016-07-22 00:05:57
【问题描述】:
是否有任何 API 或库可供我使用 .jpgs 和 .pngs 创建 .gif?我正在寻找一个可以与 Python 3 一起使用的。
【问题讨论】:
标签: python
是否有任何 API 或库可供我使用 .jpgs 和 .pngs 创建 .gif?我正在寻找一个可以与 Python 3 一起使用的。
【问题讨论】:
标签: python
这是我不久前写的东西。当我在过去六个月写这篇文章时,我找不到更好的东西。希望这可以让你开始。它使用了 here! 找到的 ImageMagick
import os, sys
import glob
dataDir = 'directory of image files' #must contain only image files
#change directory gif directory
os.chdir(dataDir)
#Create txt file for gif command
fileList = glob.glob('*') #star grabs everything, can change to *.png for only png files
fileList.sort()
#writes txt file
file = open('blob_fileList.txt', 'w')
for item in fileList:
file.write("%s\n" % item)
file.close()
#verifies correct convert command is being used, then converts gif and png to new gif
os.system('SETLOCAL EnableDelayedExpansion')
os.system('SET IMCONV="C:\Program Files\ImageMagick-6.9.1-Q16\Convert"')
# The following line is where you can set delay of images (100)
os.system('%IMCONV% -delay 100 @fileList.txt theblob.gif')
新的转换通话
无论出于何种原因(我没有查看差异),我不再需要代码中的 set local 和 set 命令行。我以前需要它,因为即使设置了路径也没有使用转换命令。当您使用新的 7.. 版本的图像魔法时。请参阅新的代码行以替换最后三行。 请务必选中要求下载旧命令的复选框,例如安装时转换。一切都被转换成一个单一的魔法命令,但我不想重新学习新的约定。
os.system('convert -delay 50 @fileList.txt animated.gif')
【讨论】: