Simple Animated GIF Problem

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
doubleg

Simple Animated GIF Problem

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Simple Animated GIF Problem

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
doubleg

Re: Simple Animated GIF Problem

Post by doubleg »

Anthony,

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