Page 1 of 1

$image->Coalesce(); isn't doing anything

Posted: 2019-03-25T03:50:02-07:00
by ufuw
I used this command

Code: Select all

convert anim.gif -coalesce -resize 24x24 +append anim.png
to turn animated gifs into spritesheets that fit into a 24x24 square. I got tired of doing this, so I've decided to automate my workflow and put it into a Perl script. However, I cannot, for the life of me, get the coalesce function to work in Perl. My code is as follows:

Code: Select all

my $image = Image::Magick->new(background=>"rgba(0, 0, 0, 0.0)", alpha=>"On");
$image->Read("anim.gif");
$image->Coalesce();
$image->Resize(geometry=>"24x24");
$image->Append(stack=>0);
$image->Write(format=>"png", filename=>"anim.png");
undef $image;
The dimensions are correct, but when anim.gif is optimized, transparent holes show up all over the spritesheet, rendering it unusable. I am fairly sure that the problem lies within the coalesce function, as that is what it is supposed to prevent.

Re: $image->Coalesce(); isn't doing anything

Posted: 2019-03-25T10:02:33-07:00
by fmw42
What is your IM version and platform/OS? Can you post a link to your animated gif?

Re: $image->Coalesce(); isn't doing anything

Posted: 2019-03-25T12:34:25-07:00
by ufuw
I am running ImageMagick 7.0.8-34 Q16 x86_64 2019-03-15 on a fully updated Arch Linux. Here is the full animated gif: (link is https://cdn.discordapp.com/emojis/55478 ... 924370.gif)
Image

Re: $image->Coalesce(); isn't doing anything

Posted: 2019-03-25T17:13:07-07:00
by magick

Code: Select all

use Image::Magick;

my $image = Image::Magick->new(background=>"rgba(0, 0, 0, 0.0)", alpha=>"On");
$image->Read("anim.gif");
$coalesce=$image->Coalesce();
$coalesce->Resize(geometry=>"24x24");
$append=$coalesce->Append(stack=>0);
$append->Write(format=>"png", filename=>"anim.png");
undef $image;

Re: $image->Coalesce(); isn't doing anything

Posted: 2019-03-25T17:37:32-07:00
by ufuw
My mistake, I didn't realize that coalesce didn't transform in place. Thank you for the response :D