在python中使用imageio从图像制作gif [英] making gif from images using imageio in python
本文介绍了在python中使用imageio从图像制作gif的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在网上阅读了很多示例,发现 imageio
是完美的包.还在这里找到了示例.
I have tried reading a lot of examples online and found imageio
is the perfect package for it. Also found examples written in here.
我刚刚按照所示的示例进行操作并尝试了以下操作
I have just followed the example as shown and tried the following
import imageio as io
import os
file_names = sorted((fn for fn in os.listdir('.') if fn.startswith('surface')))
#making animation
with io.get_writer('surface.gif', mode='I', duration=0.5) as writer:
for filename in file_names:
image = io.imread(filename)
writer.append_data(image)
writer.close()
还有一个例子.
images = []
for filename in file_names:
images.append(io.imread(filename))
io.mimsave('surface1.gif', images, duration = 0.5)
这两个都不起作用.基本上我只看到 gif 的第一帧,然后眨眼就完成了.持续时间设置为 0.5 秒,所以它应该可以正常工作.我可能在这里错过了一些东西.
both of these do not work. And basically i only see the first frame from the gif and a blink and finish. The duration is set 0.5secs, so it should work fine. I might have been missing out something here.
推荐答案
这对我有用:
import os
import imageio
png_dir = '../animation/png'
images = []
for file_name in sorted(os.listdir(png_dir)):
if file_name.endswith('.png'):
file_path = os.path.join(png_dir, file_name)
images.append(imageio.imread(file_path))
imageio.mimsave('../animation/gif/movie.gif', images)
这篇关于在python中使用imageio从图像制作gif的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文