Composite() bug, mask won't unset, causes crash in WinXP
Posted: 2008-06-11T00:17:26-07:00
When I write a script that uses a mask image when compositing onto another image, the mask stays with the base image and masks any further Composite()s unless I remove it using Set(mask=>""). I don't remember this being the case in past scripts, so I'm not sure if that's a bug or not, but as long as I can get rid of the mask, it's OK. However, using Set(mask=>"") works on my web host's installation, but causes the Perl interpreter to crash under Windows XP. Both my web host and my local machine have ImageMagick 6.4.1 Q16 installed. My local machine is running Windows XP SP3 with ActivePerl 5.10.0 Build 1002; my web host is running Linux 2.6.9-55.0.2.ELsmp, with Perl v5.8.8 built for i686-linux.
Here's the Perl code I'm running:
You can see the script in action:
This version demonstrates the persistent masking behavior (it doesn't use the Set(mask=>"") line); this version demonstrates shows what happens when Set(mask=>"") is used. This is the base image, this is the mask image, this is the overlay image.
Here's the Perl code I'm running:
Code: Select all
#!/usr/bin/perl
use Image::Magick;
$base = Image::Magick->new;
$base->Set(size=>"400x300");
$base->Read("sign01-base.png");
$tint = Image::Magick->new;
$tint->Set(size=>"400x300",matte=>'True');
$tint->Read("xc:#2C8259");
$mask = Image::Magick->new;
$mask->Set(size=>"400x300");
$mask->Read("sign01-header-bg-mask.gif");
$base->Composite(image=>$tint,compose=>'Over',mask=>$mask,x=>0,y=>0,gravity=>'NorthWest');
undef $mask;
# the following line works under Linux but causes Perl to crash under Windows XP
$base->Set(mask=>"");
$overlay = Image::Magick->new;
$overlay->Set(size=>"400x300");
$overlay->Read("sign01-overlay.png");
$base->Composite(image=>$overlay,compose=>'Over',x=>0,y=>0,gravity=>'NorthWest');
undef $overlay;
print "Content-Type: image/jpeg;\n\n";
binmode STDOUT;
$base->Set(compression=>'JPEG',quality=>'85');
$base->Write('jpg:-');
undef $base;
This version demonstrates the persistent masking behavior (it doesn't use the Set(mask=>"") line); this version demonstrates shows what happens when Set(mask=>"") is used. This is the base image, this is the mask image, this is the overlay image.