commandline option "-draw" : animated GIF not working?

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
butz74

commandline option "-draw" : animated GIF not working?

Post by butz74 »

Hi,

I tried to create a thumbnail of a animated GIF with following command.

Target:
1. create a transparent canvas with the size of 32 x 32 px (-size 32x32 xc:"transparent") : OK
2. placing the animated GIF at this canvas with given position (-draw "image over 4,4 24,24 'anim.gif'") : NOK

Command:
convert -size 32x32 xc:"transparent" -draw "image over 4,4 24,24 'anim.gif'" out-anim.gif

Problem:
The animation is within out-anim.gif gone, only the first layer of the animated GIF (anim.gif) is shown.
Is there a problem, using the "-draw" option with a animated GIF?

/usr/bin/convert -version
Version: ImageMagick 6.4.1 05/27/08 Q16

Thanks and greetings!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: commandline option "-draw" : animated GIF not working?

Post by fmw42 »

you have to separate the frames (-coalesce) and overlay and then recombine ( I think). see

http://www.imagemagick.org/Usage/anim_basics/
http://www.imagemagick.org/Usage/anim_mods/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: commandline option "-draw" : animated GIF not working?

Post by anthony »

Animations have multiple 'frames' or images. They are also often 'optimised' so as to try to save disk space, but that makes the images in individual frames incomplete or 'bad' looking.

First use -coalesce to remove the optimization from the animation!

You can not use -draw to compose multiple images onto a single image, though you can use it to compose a single image onto (or under) multiple images. See
http://www.imagemagick.org/Usage/anim_m ... mpose_draw

You can't even use composite or -composite, as again these only do two images at a time, instead you should use -layers composite, which not only allows the merging to two image sequences of equal numer of frames, but also the merging of a image sequence with a single image. See..
http://www.imagemagick.org/Usage/anim_mods/#composite
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
butz74

Re: commandline option "-draw" : animated GIF not working?

Post by butz74 »

Dear Anthony

Thank you for your quick reply!

After reading the superb documentation (seems to be a "tough" thing, this anim-gif-thing ... !), I ended within the following command:

convert -size 32x32 xc:"transparent" null: \( anim.gif -coalesce -thumbnail '32x32>' \) -gravity center -layers composite out-anim.gif

which seems to produce the wanted GIF. Have I the documentation correct interpreted? What you think?

Thank you anyway for your help!

Greetings
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: commandline option "-draw" : animated GIF not working?

Post by anthony »

It does not appear that you are wanting to compose you animation.

the -composite would do the task of making all the frames of your animation the same size. Composing it on to transparency would make no change to the result
except maybe to 'pad' out animation (with centering) that are smaller than 32x32.
Larger animations will be cropped, which is presumably why you have a -thumbnail resize.

Their are other simpler alternatives. such as adding a border to each coalesced frame, and then center (viewport) cropping.

The major thing you seem to be doing is to resize larger animations down to 32x32
pixels, as a animated thumbnail.

That can be tricky as resizing adds new colors and can make the resulting animations look rather horrible. See the later section on resizing.
http://www.imagemagick.org/Usage/anim_mod/#resize
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
butz74

Re: commandline option "-draw" : animated GIF not working?

Post by butz74 »

We have solved the problem with an other way, so no further help is needed. Thank you for your help in any way!!

Greetings
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: commandline option "-draw" : animated GIF not working?

Post by anthony »

Code: Select all

convert anim.gif -coalesce -thumbnail '32x32>' -gravity center -background transparent -extent 32x32 -layers Optimize out-anim.gif
should do what you want.

However -resize has other problems, especially with regards to GIF images, its limited color table, and the boolean transparency. It may be better to select a -background white (or some other appropriate color instead of -background transparency for GIF animation thumbnails.

However if your solution is working for you then good.

Can you provide us with a link to a before and after example, so I can have a look and see if I can suggest any other improvements.

NOTE -layers Optimize reduces the size of the image by doing color reduction, OptimizeFrame and OptimizeTransparency. See IM Examples Animation optimization for more information on this and various file size reduction techniques.
http://www.imagemagick.org/Usage/anim_opt/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
butz74

Re: commandline option "-draw" : animated GIF not working?

Post by butz74 »

Because the "whole thing" is executed within a web CMS, I cann't provide you a link to a source (is there instead a file upload?), sorry.

My solution was to check if the user is defining a clipping on the source image (offset x/y);

if ($offsetX == 0 && $offsetY == 0) {
$command .= ' null: \\( \''. $params['imagePath'] .'\' -coalesce -thumbnail \''. $imageW .'x'. $imageH .'>\' \\) -gravity center -layers composite';
}
else {
$command .= ' -draw "image over '.$offsetX.','.$offsetY.' '.$imageW.','.$imageH.' \''.$params['imagePath'].'\'"';
}

Greetings
Post Reply