Page 1 of 1

PerlMagick: Count frames in animated GIF?

Posted: 2009-12-13T19:52:32-07:00
by Hatch
Seems like this should be simple, but an hour or so of googling has only turned up oblique references to ways of doing this with the command line tools, and I couldn't translate them to perl. Any help would be greatly appreciated.

EDIT: Oops! I didn't notice the subforum specifically for PerlMagick. Feel free to move; sorry for the trouble.

Re: PerlMagick: Count frames in animated GIF?

Posted: 2009-12-13T20:04:18-07:00
by fmw42
in command line in unix, I would do

#create 4 frame gif
convert rose: rose: rose: rose: rose4.gif

#get number of frames
convert rose4.gif -format "%[scenes]" info: | tail -n 1
4

or

convert rose4.gif -format "%n" info: | tail -n 1
4


#get last frame number (frame numbers start at 0)
convert rose4.gif[-1] -format "%[scene]" info:
3

see string formats http://www.imagemagick.org/script/escape.p


Don't know what the equivalent is in perlmagic?

Re: PerlMagick: Count frames in animated GIF?

Posted: 2009-12-15T08:31:32-07:00
by Hatch
The PerlMagick page only mentions those -format properties as they relate to the Annotate(), Comment(), Draw(), and Label() methods. I can't figure out any way to access them directly. It's possible I'm missing something obvious.

EDIT: Aha! I figured it out. It's actually quite simple:

Code: Select all

my $frames = $image->Get(text=>"%n");
And that works for most or all of the -format properties. Perhaps this could be explained on the PerlMagick page since it's not exactly obvious, or at least it wasn't to me.