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.
PerlMagick: Count frames in animated GIF?
PerlMagick: Count frames in animated GIF?
Last edited by Hatch on 2009-12-13T20:22:14-07:00, edited 1 time in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PerlMagick: Count frames in animated GIF?
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?
#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?
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:
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.
EDIT: Aha! I figured it out. It's actually quite simple:
Code: Select all
my $frames = $image->Get(text=>"%n");