Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a pause between loops of a GIF? #1073

Open
Miguel-LlamasLanza opened this issue Apr 4, 2024 · 1 comment
Open

How to add a pause between loops of a GIF? #1073

Miguel-LlamasLanza opened this issue Apr 4, 2024 · 1 comment

Comments

@Miguel-LlamasLanza
Copy link

I use imageio.mimsave("fname.gif", frames, loop=4) to save a GIF from python plots. I would like to add a pause between each loop. Is this possible?

@Pandede
Copy link
Contributor

Pandede commented Apr 5, 2024

Use optional argument duration (Reference), it accepts float for all frames or list for one value of each frame.
Pausing the GIF between loops can be done via this tricky method:

import imageio.v2 as iio

frames = iio.mimread("imageio:newtonscradle.gif")
# The default duration of each frame
default_duration = 50
# The lagging
lag = 1000
# Pause the GIF by extending the duration of the last frame
duration = [default_duration] * (len(frames)-1) + [lag]
iio.mimwrite('paused.gif', frames, loop=4, duration=duration)

paused

Note that, you may find out the frame duration with imageio.v3.immeta:

import imageio.v3 as iio
meta = iio.immeta("imageio:newtonscradle.gif")
print(meta['duration'])  # 50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants