How to determine the length of a .gif animation in milliseconds

后端 未结 3 1942
清酒与你
清酒与你 2021-01-13 22:19

Is there an easy way to figure out approximately how long a .gif image takes to play one time in Javascript?

3条回答
  •  醉酒成梦
    2021-01-13 22:38

    The accepted answer doesn't give the exact result. Elapsed time is like a real world clock while ImageMagick runs the animation. What you want is the Delay field for each frame and sum them up.

    $ identify -verbose fail.gif  | grep Delay
    
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 15x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    Delay: 33x100
    Delay: 10x100
    Delay: 10x100
    Delay: 10x100
    

    Where 33x100 is a delay of 330ms.

    Edited by Mark Setchell

    You can actually extract the delay parameter somewhat more surgically (than by using grep) with the %T escape:

    identify -format "%T\n" animation.gif 
    
    8
    8
    8
    8
    8
    8
    8
    8
    8
    8
    11
    11
    11
    11
    11
    11
    11
    26
    

    And get the total with awk like this:

    identify -format "%T\n" anomation.gif | awk '{t+=$0} END{print t " centiseconds"}'
    183 centiseconds
    

提交回复
热议问题