Page 1 of 1

Simple Animated GIF Problem

Posted: 2009-05-02T20:31:02-07:00
by doubleg
Hello,

I'm using ImageMagick 'system' style commands inside a Perl script. I have successfully taken an animated GIF and broken it into individual frames with IM using something like:

system("/usr/local/bin/convert", "+adjoin", "-coalesce", "orig.gif", "frame_%02d.gif");

As expected, I get the individual frames, i.e. "frame_00.gif", "frame_01.gif", etc.

I then take those individual frames and crop them by looping with a command like:

system("/usr/local/bin/convert", "frame_00.gif", "-crop", "$cropw x $croph + $cropx + $cropy\!", "cframe0.gif");
system("/usr/local/bin/convert", "frame_01.gif", "-crop", "$cropw x $croph + $cropx + $cropy\!", "cframe1.gif");
etc.

This also works, and I get a bunch of cropped frames. These are 320x240 gif images and each will open in image editors and browsers, so I guess they're OK.

Now, I want to re-join the cropped frames into a new animated gif. Here is where I can't seem to get a command working to create the new animated gif. Ive tried (amongst other things) calls like:

system("/usr/local/bin/convert", "-delay 25", "-loop 0", "cframe0.gif", "cframe1.gif", "cframe2.gif", "anim.gif");
and
system("/usr/local/bin/convert", "-delay 25", "-loop 0", "cframe*.gif", "anim.gif");

The "anim.gif" file just isn't created. I'm a total NEWB at this (and surprised I've made it this far), but now I'm stuck. Any help would be appreciated. Thanks.

Re: Simple Animated GIF Problem

Posted: 2009-05-02T23:32:07-07:00
by anthony
The "-loop", "0" remember 0 is a separate option argument. Having it as you have it, would be a syntax error (which you probably have in your web servers log)

I would also move -loop 0 to just before the final write seeing that is where it is needed.


As for cropping animations see...
IM examples, Animation Modifications, Cropping (two sections of examples)
http://www.imagemagick.org/Usage/anim_mods/#crop

PS: -coalesce can be very important. See previous sections.

Re: Simple Animated GIF Problem

Posted: 2009-05-03T08:43:56-07:00
by doubleg
Anthony,

The syntax help and crop example are EXACTLY what I needed. Much appreciated!