0

I am trying to use both ImageIo and PIL to save a sequence of my images as GIF. The images do get saved in a .gif file. But, they are getting saved as a sequence of images and not as a "video" GIF.

gif_images[0].save('path/test.gif', save_all=True, append_images=gif_images[1:], optimize=False, duration=40, loop=0) #using PIL
imageio.mimsave('path/test.gif', gif_images, format = 'GIF', fps=10) #using imageio

gif_images is a list of <class 'PIL.JpegImagePlugin.JpegImageFile'> image files.

I have tried varying fps rates, durations but nothing seems to work.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • 1
    Please click [edit] and ensure you provide a **complete** [mcve] with `import` statements and a proper example, even if it is only 3 dummy frames, one red, one green and one blue. Thank you. – Mark Setchell Nov 11 '22 at 08:51

1 Answers1

0

I would recommend that you switch to using ImageIO's v3 API. The syntax is a little cleaner:

import imageio.v3 as iio

iio.imwrite("path/test.gif", gif_images, duration=100, loop=0)
# duration is the time to display each frame in ms

That said, the reason you are seeing a "sequence of images" instead of a video is likely because you are playing the video at 10 FPS. At this framerate most people will be able to perceive individual frames.

There could be other reasons, but without seeing a full example and the images in question this is hard to say for certain.

FirefoxMetzger
  • 2,880
  • 1
  • 18
  • 32