简体   繁体   中英

making gif from images using imageio in python

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()

and another example.

images = []
for filename in file_names:
    images.append(io.imread(filename))
io.mimsave('surface1.gif', images, duration = 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.

This works for me:

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 3.6.8,它需要fps

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM