Preserving Alpha with MagickCompositeImage
Posted: 2013-04-13T09:05:18-07:00
I'm using MagickCompositeImage to read in a "border" image which has some partial transparency in it, but when I composite it onto my background, the partial transparency is turned to black, but the fully transparent parts are still transparent.
Any tips on what I'm doing wrong?
I tried using MW_CopyOpacityCompositeOp instead of MW_OverCompositeOp when copying the border but then it just seems to copy nothing at all.
Any tips on what I'm doing wrong?
Code: Select all
// Read in images
$image_body = NewMagickWand();
$image_header = NewMagickWand();
$border_img = NewMagickWand();
MagickReadImage($image_body, "body.png");
MagickReadImage($image_header, "header.png");
MagickReadImage($border_img, "border.png");
// Create main canvas
$main_image = NewMagickWand();
MagickSetFormat($main_image, 'PNG24');
$transparent = NewPixelWand();
PixelSetColor($transparent, 'none');
MagickNewImage($main_image, 350, 150, $transparent);
MagickCompositeImage($main_image, $image_body, MW_OverCompositeOp, 2, 26);
MagickCompositeImage($main_image, $image_header, MW_OverCompositeOp, 2, 2);
MagickCompositeImage($main_image, $border_img, MW_OverCompositeOp, 0, 0);
header("Content-Type: image/png");
MagickEchoImageBlob($main_image);