我一直在玩Python的动画GIF,其中帧将由位于温室中的树莓派相机产生。我使用了Almar's answer to a previous question中推荐的imageio代码,并成功创建了简单的gif。Python中动画GIF的自定义帧持续时间ImageIO
但是,我现在试图减慢帧持续时间,但看着documentation for imageio,找不到任何引用mimsave,但看到mimwrite,应该采取四个参数。我查看了additional gif documentation,可以看到有一个持续时间参数。
目前,我的代码如下所示:
exportname = "output.gif"
kargs = { 'duration': 5 }
imageio.mimsave(exportname, frames, 'GIF', kargs)
,我发现了以下错误:
Traceback (most recent call last):
File "makegif.py", line 23, in <module>
imageio.mimsave(exportname, frames, 'GIF', kargs)
TypeError: mimwrite() takes at most 3 arguments (4 given)
,其中帧是imageio.imread对象的列表。为什么是这样?
已更新才能显示完整答案: 这是一个显示如何使用kwargs创建带有imageio的动画gif以更改帧持续时间的示例。
import imageio
import os
import sys
if len(sys.argv) < 2:
print("Not enough args - add the full path")
indir = sys.argv[1]
frames = []
# Load each file into a list
for root, dirs, filenames in os.walk(indir):
for filename in filenames:
if filename.endswith(".jpg"):
print(filename)
frames.append(imageio.imread(indir + "/" + filename))
# Save them as frames into a gif
exportname = "output.gif"
kargs = { 'duration': 5 }
imageio.mimsave(exportname, frames, 'GIF', **kargs)
传奇。我褪色的大脑谢谢你... –