我一直在玩
Python中的GIF动画,框架将由位于温室中的Raspberry Pi相机生成.我已经使用
Almar’s answer to a previous question推荐的imageio代码成功创建了简单的GIF.
但是,我现在正试图减慢帧持续时间,但是看看documentation for imageio并且找不到mimsave的任何引用,但确实看到了mimwrite,它应该采用四个args.我看了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
imageio.mimsave(exportname, frames, 'GIF', kargs)
TypeError: mimwrite() takes at most 3 arguments (4 given)
其中frames是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)