coalesce failing on some gifs

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
meowmeow
Posts: 9
Joined: 2010-11-21T12:42:52-07:00
Authentication code: 8675308

coalesce failing on some gifs

Post by meowmeow »

I'm working with animated gifs and finding something as simple as the below is failing for some but not all animated gifs.

Code: Select all

convert $image -coalesce $output
Where values of $image is a path to an animated gifs and $output is a path to the destination.

For this gif, http://d.imagehost.org/0088/test.gif, the code outputs nothing. Must an animated gif have certain attributes for ImageMagick to process it? Is there a gif normalization that I need to do?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: coalesce failing on some gifs

Post by fmw42 »

convert test.gif -coalesce test2.gif

works just fine if you wait long enough for the processing. I am using IM 6.6.5-8 Q16 Mac OSX Tiger.

If you have an old version of IM (which you did not identify), perhaps you need to upgrade.
meowmeow
Posts: 9
Joined: 2010-11-21T12:42:52-07:00
Authentication code: 8675308

Re: coalesce failing on some gifs

Post by meowmeow »

Ah, my mistake- I uploaded one of the animated gifs I was testing that worked rather than one that doesn't. Please look at this one instead: http://d.imagehost.org/0350/bettertest.gif
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: coalesce failing on some gifs

Post by anthony »

Your GIF "bettertest.gif" image appears to be fully coalesced already. No transparency, no sub-frame optimization!

It is also VERY large. for a GIF animation with a very very very small delay! That is not very nice!
It also have undefined disposals, which usually means to use 'None' disposal.

When I rung -coalesce on it the disposal was set properly to 'None' and everything else is as it should be. It remained a fully-coalesced' or film-stripe like overlay animation!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
meowmeow
Posts: 9
Joined: 2010-11-21T12:42:52-07:00
Authentication code: 8675308

Re: coalesce failing on some gifs

Post by meowmeow »

So its the size of the file that is the problem? I'd love to optimize them or scale the image size, but any commands I attempt to execute on them output nothing. Both of these fail:

Code: Select all

convert $image -layers optimize output.gif

Code: Select all

convert $image -resize 32x32 output.gif
Is there a way to increase ImageMagick's file size tolerance? Or another way to process these animated gifs?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: coalesce failing on some gifs

Post by anthony »

I had no problems converting or processing them. And even on machines that have limited memory IM can switch to slower disk based storage to get around it.

What version of IM are you using. It may be very old!

As for your problem look at the section of Video Handling, Video to GIF, Optimization Summary
http://www.imagemagick.org/Usage/video/

I noticed that you were already using a ordered dither on the video to prevent dither noise, so that is a good start.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
meowmeow
Posts: 9
Joined: 2010-11-21T12:42:52-07:00
Authentication code: 8675308

Re: coalesce failing on some gifs

Post by meowmeow »

My host (HostGator) is running version 6.6.0 rather than 6.6.5. Is that problem enough to make a difference?

Code: Select all

$image = "http://d.imagehost.org/0088/test.gif";
$watermark = "http://www.accessibletwitter.com/images/iconsSocial/twitter.png";

$exec = "convert $image -resize 32x32 -layers optimize output1.gif";
exec($exec, $out, $ret); //echo $ret; print_r( $out );
echo "<hr /> $exec <hr />  <img src='output1.gif' />";

$exec = "convert $image -resize 256x256 -layers optimize output2.gif";
exec($exec, $out, $ret); //echo $ret; print_r( $out );
echo "<hr /> $exec <hr />  <img src='output2.gif' />";

$exec = "convert $image -layers optimize output3.gif";
exec($exec, $out, $ret); //echo $ret; print_r( $out );
echo "<hr /> $exec <hr />  <img src='output3.gif' />";

$exec = "convert $image -coalesce -gravity Center -geometry +0+0 null: $watermark -layers composite -layers optimize output4.gif";
exec($exec, $out, $ret); //echo $ret; print_r( $out );
echo "<hr /> $exec <hr />  <img src='output4.gif' />";
In the above code, the first command works but the other three do not. The fourth is pretty much the goal of my work. Any idea?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: coalesce failing on some gifs

Post by fmw42 »

I would not think the version would a problem, but one never knows if there was a bug at that time. Can you do it on the command line successfully as I did? I am not much of PHP person to be able to critique your code. But others, like user Bonzo, may be able to help (rubblewebs.com)

One comment == are you sure that your are actually accessing the http image via PHP? PHP may limit your ability to do that. But again I don't know PHP that well.
meowmeow
Posts: 9
Joined: 2010-11-21T12:42:52-07:00
Authentication code: 8675308

Re: coalesce failing on some gifs

Post by meowmeow »

I'm going to open a ticket with HostGator to see if they have any thoughts regarding the version issue. All of the code works with SOME gifs and the first section of code works with all gifs so it is definitely accessing the images correctly. I've even ran this with server relative paths to the images and depending on the gif, it produced the same results.

I feel like there is something I need to do to these gifs to prep them for the more complicated code (output4.gif). If I first use IM to make the gifs tiny, it runs fine.

Code: Select all

convert http://d.imagehost.org/0088/test.gif -resize 50x50 -coalesce -gravity Center -geometry +0+0 null: http://www.accessibletwitter.com/images/iconsSocial/twitter.png -layers composite -layers optimize output1.gif 
Again the above code works as expected but I cannot use a 50x33 image. I need the gif to remain its original size (360x240).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: coalesce failing on some gifs

Post by fmw42 »

try putting the -resize after the -coalesce. gif frames may not all be the same size until you do the coalesce.
meowmeow
Posts: 9
Joined: 2010-11-21T12:42:52-07:00
Authentication code: 8675308

Re: coalesce failing on some gifs

Post by meowmeow »

That command works either way (resize first and coalesce first).

My goal is to simply add a png to every frame of any given animated gif. The script below works for some gifs, but not the gif below:

Code: Select all

convert http://d.imagehost.org/0088/test.gif -coalesce -gravity Center -geometry +0+0 null: http://www.accessibletwitter.com/images/iconsSocial/twitter.png -layers composite -layers optimize output4.gif 
Does the above work for anyone with their configuration?
meowmeow
Posts: 9
Joined: 2010-11-21T12:42:52-07:00
Authentication code: 8675308

Re: coalesce failing on some gifs

Post by meowmeow »

Response from host:

The issue here is with memory allocation. Those processes exceeded the allowed user memory and so won't work with any version of ImageMagick.

Code: Select all

[Tue Nov 23 06:54:31 2010] [error] [client 66.45.229.82] convert: memory allocation failed `/tmp/magick-XXhzQRHZ' @ error/quantize.c/QuantizeImages/2603.
[Tue Nov 23 06:54:34 2010] [error] [client 66.45.229.82] convert: memory allocation failed `/tmp/magick-XXWMRwGW' @ error/quantize.c/QuantizeImages/2603. 
Is it possible to work around this? Is there a way to break the gif apart, add my image to the frames of the sub gifs, then reassemble it?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: coalesce failing on some gifs

Post by fmw42 »

Post Reply