Get gif duration?

Just starting out? Need help? Post your questions and find answers here.
vwidmer
Enthusiast
Enthusiast
Posts: 286
Joined: Mon Jan 20, 2014 6:32 pm

Get gif duration?

Post by vwidmer »

Is there a simple way to get the duration of a gif?

like this gif is 4secs long?
WARNING: I dont know what I am doing! I just put stuff here and there and sometimes like magic it works. So please improve on my code and post your changes so I can learn more. TIA
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Get gif duration?

Post by Paul »

This is pretty simple using the Image library commands...

Code: Select all

UseGIFImageDecoder()

gif=LoadImage(#PB_Any,"mygif.gif")
If gif
  frames=ImageFrameCount(gif)
  If frames>1
    For idx=1 To frames
      SetImageFrame(gif,idx-1)
      delay+GetImageFrameDelay(gif)
    Next
  EndIf
  
  Debug "Frames: "+frames
  Debug "Total ms: "+delay
  
  FreeImage(gif)
EndIf
Image Image
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Get gif duration?

Post by infratec »

You need to read the headers of each frame and add the DelayTimes.

Ok, to late.
Post Reply