My webhost updated to the latest version of ImageMagick a few days ago (6.3.6) and this caused a bunch of my ImageMagick perl scripts to break. Before, I was able to composite using a greyscale PNG as an alpha mask; specifically, I would allow the user to choose a color, I would create an image handle and fill it with that color, create another image handle and load the PNG image into it, and composite the filled image onto a third base image using the PNG as a mask:
Code: Select all
// create the base image;
$base = Image::Magick->new;
$base->Set(size=>"$imgsize");
$base->Read("xc:#$imgbgcolor");
// create the 'fill' image
$tints{"$bgcolor"} = Image::Magick->new;
$tints{"$bgcolor"}->Set(size=>"$imgsize");
$tints{"$bgcolor"}->Read("xc:#$bgcolor");
// create the mask image
$bgmask = Image::Magick->new;
$bgmask->Set(size=>$imgsize);
$bgmask->Read("images/art-web/bg-fill.png");
// composite the 'fill' image onto the base image using the PNG as a mask
$base->Composite(image=>$tints{"$bgcolor"},compose=>'Over',mask=>$bgmask,x=>0,y=>0,gravity=>'NorthWest');
Then the image will be output as a GIF, and it'll appear as the shape in the PNG image composited onto the background image in the user-specified color. After the upgrade, it appears as a single-color image, in the user-specified color, as if the mask didn't work (or was all white). However (and this is the oddest part) if I resize $base before I output it as a GIF, it looks fine (albeit at a different size). If I output it as a PNG instead of as a GIF, it looks fine. But if I output it as a GIF, it's a solid color. Did something about alpha compositing or outputting to an 8-bit graphic change in the latest version?