我imageio
用来从使用 PIL 创建的一组 PNG 生成 GIF。这是我的代码(在这里找到):
import imageio
path = "./img/"
os.chdir(path)
filenames = sorted((fn for fn in os.listdir('.') if fn.endswith('.png')))
with imageio.get_writer('./img/movie.gif', mode='I') as writer:
for filename in filenames:
image = imageio.mimread(filename)
writer.append_data(image)
但是,我不断收到以下错误:
Traceback (most recent call last):
File "gifcreate.py", line 7, in <module>
image = imageio.mimread(filename)
File "/Users/felipe_campos/Documents/DECO/venv/lib/python2.7/site-packages/imageio/core/functions.py", line 261, in mimread
reader = read(uri, format, 'I', **kwargs)
File "/Users/felipe_campos/Documents/DECO/venv/lib/python2.7/site-packages/imageio/core/functions.py", line 108, in get_reader
'in mode %r' % mode)
ValueError: Could not find a format to read the specified file in mode 'I'
有人对我能做什么有任何想法吗?我尝试在虚拟环境之外运行它,但它一直告诉我ImportError: No module named imageio
(与 scipy 和其他一些模块相同),所以我不知道该怎么做。
编辑:
想通了,只需使用 imread(filename) 而不是 mimread(filename) 就可以了。