Git Product home page Git Product logo

Comments (9)

photopea avatar photopea commented on July 22, 2024

It took me a lot of struggle, but here is how Looping in GIFs work (or at least how browsers interpret it):

  • to repeat forever, there should be the Netscape block containing 0
  • to repeat just once, there should be no Netscape block
  • to repeat N times (1<N), there should be a Netscape block containing N-1

Maybe you could make the "loop" input of GifWriter ("loop" output of GifReader) represent a true number of loops, and read/write it correspondingly? You could keep 0 as Forever.

from omggif.

deanm avatar deanm commented on July 22, 2024

Just to make sure I understand now, if you set loop to undefined on the GifWriter options, it behaves correctly and plays once? If you set loop to 3 it loops 4 times?

from omggif.

deanm avatar deanm commented on July 22, 2024

I know it's a little inconvenient, but my intention with the library was to be as low level on top of the GIF format as possible, meaning it basically just handles writing out the format and doing the compression, but not much else, and gives the user fairly direct control over the output of the GIF file, etc. I think the first thing is just to document this clearly. Then I would still like loop to mean "this is the value that gets written into the GIF file", but there could definitely be an additional helper function like gifLoopValueToActualPlayCount (okay needs a better name) that will return the proper loop value (including returning undefined/null for no block) for the actual number of times you want it to play, and the reverse calculation for reading.

from omggif.

photopea avatar photopea commented on July 22, 2024

Ok, I understand. But I just expected the "loop" property be the number of times the GIF repeats.

I could not find how this property works anywhere on the internet, so I discovered it by testing.

from omggif.

deanm avatar deanm commented on July 22, 2024

I think it's a manner of terminology. "loop" is the process of restarting to the beginning after hitting the end, so if something loops once it plays twice. So the play count is not the same as the loop count, the loop count is 1 less than the play count. Again if something "repeats" once it means in total it plays twice (the first one and then the 1 repeat). Does this make sense and match the behaviour you described?

from omggif.

photopea avatar photopea commented on July 22, 2024

Thats an interesting theory :D But loop=0 repeats forever .. should not it repeat just once? :D

from omggif.

deanm avatar deanm commented on July 22, 2024

Looping was added later (it's an extension block). Without any looping a gif will always play once, so the only question was how many additional times will it play. Therefore instead of adding some additional way of saying loop forever, they just made loop of 0 mean loop forever.

from omggif.

photopea avatar photopea commented on July 22, 2024

I understand, that they made it work in a certain way.

I am just saying, that your idea, that they intended to make the loop number correspond to the number of times skipping back, is very unprobable.

from omggif.

deanm avatar deanm commented on July 22, 2024

Don't know why you think it is unlikely, I am certain this is how it was designed.

I can't dig up the original Netscape references, but this is from the gifsicle code from the late 90s.

https://www.lcdf.org/gifsicle/man.html

--loopcount[=count]
Set the Netscape loop extension to count. Count is an integer, or forever to loop endlessly. If you supply a --loopcount option without specifying count, Gifsicle will use forever. --no-loopcount (the default) turns off looping. 

Set the loop count to one less than the number of times you want the animation to run. An animation with --no-loopcount will show every frame once; --loopcount=1 will loop once, thus showing every frame twice; and so forth. Note that --loopcount=0 is equivalent to --loopcount=forever, not --no-loopcount. 

"--loopcount=1 will loop once, thus showing every frame twice"

from omggif.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.