使用不循环的PIL创建动画gif

时间:2019-02-11 00:34:49

标签: python python-imaging-library gifsicle

我已经能够创建动画gif,这些gif可以使用PIL无限循环,而不会出现问题,通常以

结尾

final_image.save('/path/to/images/some.gif, save_all=True, append_images=frames_images, duration=frame_speeds, loop=0)

我现在处于一种情况,我想创建一个可以播放一次且不会循环播放的gif。我使用的PIL文档¹非常清楚关于loop参数,但没有针对我的情况提供任何建议:

  

loop:int
  迭代次数。默认值为0(无限循环)。

0使其无限循环。 1使其循环一次(播放两次)。我尝试了-1和None之类的选项,但是找不到有效的参数。我目前正在使用一种解决方法,之后再调用gifsicle来完全删除循环,但希望PIL可以原生支持此功能

¹-https://imageio.readthedocs.io/en/stable/format_gif-pil.html

1 个答案:

答案 0 :(得分:0)

如果您使用的是Pillow,则可以省略loop参数。这样可以确保没有循环。 https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#saving 还要注意,持续时间以毫秒为单位,而不是秒。