如何创建一个只播放一次的gif动画

huangapple go评论86阅读模式
英文:

How to create a gif animation that plays only once

问题

我正在尝试生成一个只播放一次帧的动画gif。

当我将LoopCount设置为1时,它会播放两次帧。当我将LoopCount设置为0或-1时,它会无限循环。

img := image.(*image.Paletted)

outGif := &gif.GIF{}
outGif.LoopCount = 0
outGif.Image = append(outGif.Image, img)
outGif.Delay = append(outGif.Delay, 10)

f, err := os.Create("/tmp/test.gif")
if err != nil {
    panic(err)
}
defer f.Close()

gif.EncodeAll(f, outGif)

如何确保它只播放一次帧?

英文:

I am trying to generate an animated gif that plays the frames only once.

When I set LoopCount to 1, it plays the frames twice. When I set LoopCount to 0 or -1, it loops infinitely.

img := image.(*image.Paletted)

outGif := &gif.GIF{}
outGif.LoopCount = 0
outGif.Image = append(outGif.Image, img)
outGif.Delay = append(outGif.Delay, 10)

f, err := os.Create("/tmp/test.gif")
if err != nil {
    panic(err)
}
defer f.Close()

gif.EncodeAll(f, outGif)

How to I make sure it only plays the frames once?

答案1

得分: 0

浏览器对循环计数器的解释有所不同。对于单个循环的gif动画,Chrome循环两次,而Firefox只播放一次动画。

请参阅GifCreator - 无法创建非循环GIF图像的问题

英文:

Browsers interpret differently the loop counter. For a single loop gif, Chrome is looping twice while Firefox is playing the animation exactly once.

See this issue of GifCreator - Unable to create non loop GIF image.

huangapple
  • 本文由 发表于 2016年3月15日 07:33:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/36000041.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定