Creating gif from images using imageio in python

I tried to read many examples on the Internet and found that imageio is the perfect package for it. Also found are examples written here .

I just followed suit 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() 

and another example.

 images = [] for filename in file_names: images.append(io.imread(filename)) io.mimsave('surface1.gif', images, duration = 0.5) 

both of them do not work. And basically, I only see the first frame from the gif and blink and end. The duration is set to 0.5 s, so it should work fine. Maybe I missed something.

+10
source share
2 answers

This works for me:

 import os import imageio png_dir = '../saves/png/' images = [] for file_name in 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('../saves/gif/movie.gif', images) 
+7
source

if someone needs it, for python 3.6.8 it needs fps

 imageio.mimsave('/path/file.gif',images,fps=55) 
0
source

Source: https://habr.com/ru/post/1013301/


All Articles