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

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
ufuw
Posts: 3
Joined: 2019-03-25T03:41:58-07:00
Authentication code: 1152

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

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

What is your IM version and platform/OS? Can you post a link to your animated gif?
ufuw
Posts: 3
Joined: 2019-03-25T03:41:58-07:00
Authentication code: 1152

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

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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;
ufuw
Posts: 3
Joined: 2019-03-25T03:41:58-07:00
Authentication code: 1152

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

Post by ufuw »

My mistake, I didn't realize that coalesce didn't transform in place. Thank you for the response :D
Post Reply