PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 17, 2022

[FIXED] How to create a gif animation that plays only once

 July 17, 2022     animated-gif, gif, go     No comments   

Issue

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?


Solution

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.



Answered By - molivier
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing