I've been able to create animated gifs that loop infinitely using PIL without an issue, usually ending up with something like
final_image.save('/path/to/images/some.gif,
save_all=True,
append_images=frames_images,
duration=frame_speeds,
loop=0)
I am now in a situation where I would like to create a gif that plays a single time and does not loop. The PIL docs I used¹ are pretty clear about the loop argument but don't offer any advice for my situation:
loop : int
The number of iterations. Default 0 (meaning loop indefinitely).
0 causes it to loop infinitely. 1 causes it loop once (play two times). I have tried options like -1 and None but can't find a working argument. I am currently using a work around where I invoke gifsicle afterwards to remove the loop entirely but was hoping PIL would support this natively
¹ - https://imageio.readthedocs.io/en/stable/format_gif-pil.html
If you are using Pillow, you can leave out the loop argument. That'll ensure no loop. https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#saving Also to note, duration is in milliseconds, not seconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With