upgrade and now broken: composite problem?

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
asonnenshine

upgrade and now broken: composite problem?

Post by asonnenshine »

I am not an IM expert but was able to make a script that worked fine for our needs. We just upgraded from IM 6.2.2 to IM 6.4.4 and now it doesn't work correctly.

Basically the script is used to created multiple sizes of transparent GIFs from a single PNG source image. The PNGs have already had the backgrounds manually cutout by hand in Photoshop. The script is designed to resize the PNG and then save as a transparent GIF, and must create a nice white matte edge so it can blend in with the white backgrounds on the website.

There may be another way to produce the same output, and I'm open to an alternate solution, but this has worked fine for over a year with no problems.

I am not 100% sure but I think the problem is related to the "composite" command.

Here is the portion of the code you should look at:

#read in the source image data
$product_image->Read("$imgpath");

#get image width
my $image_width;
$image_width = $product_image->Get("width");

#get image height
my $image_height;
$image_height = $product_image->Get("height");

#get aspect ratio (width to height)
my $aspect_ratio = $image_width / $image_height;

#determine sizing based on aspect ratio
if ($aspect_ratio>1.286 ) {
#resize the image - fixed width
$product_image->Resize(geometry=>$target_width."x");
} else {
#resize the image - fixed height
$product_image->Resize(geometry=>"x".$target_height);
}

#clone the image (so we can use as a mask)
$image_mask = $product_image->Clone();

#create a mask
$image_mask->Separate(channel=>"Opacity");

#flip the mask
$image_mask->Negate();

#blur the mask
#$image_mask->GaussianBlur("0.0x0.1");

#flatten the original image onto white bg
$flattened_image = $product_image->Flatten();

#composite the mask on top of the flattened image
$product_image->Composite(image=>$flattened_image, mask=>$image_mask);

#change the format
$imgname =~ s/png/$format/;

#write the new image to disk
$product_image->Write("$img_target_dir$imgname");
Post Reply