[Python] Creating an animated gif with PIL that does not loop

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    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

    Continue reading...

Compartilhe esta Página