COMPOSITE_MULTIPLY ignores alpha channel of src

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
jonkirkman

COMPOSITE_MULTIPLY ignores alpha channel of src

Post by jonkirkman »

It appears that compositeImage() using imagick::COMPOSITE_MULTIPLY sometimes disregards the alpha channel of the source (overlaid) image.
The only way I've gotten it to retain the alpha channel for the source (overlaid) image is to first save the overlay image to disk, open it in Photoshop and re-save it.
Has anyone found a way around this?
Thanks.
Results
Results
results.jpg (30.46 KiB) Viewed 7570 times

Code: Select all

	$grip = new Imagick('grip.png');
	
	$overlay = new Imagick();
	$overlay->newImage($grip->getimagewidth(),$grip->getimageheight(), 'blue');
	
	$overlayMask = new Imagick('mask.gif');
	
	$overlay->compositeImage($overlayMask, imagick::COMPOSITE_COPYOPACITY, 0, 0);
	
	$grip->compositeImage($overlay, imagick::COMPOSITE_MULTIPLY, 0, 0);

	$overlayMask->setImageFormat( "png" );
	$overlayMask->writeImage( 'tmp/test-overlayMask.png' );
	$overlay->setImageFormat( "png" );
	$overlay->writeImage( 'tmp/test-overlay.png' );
	$grip->setImageFormat( "png" );
	$grip->writeImage( 'tmp/test-grip.png' );
Attachments
mask.gif
mask.gif (1.7 KiB) Viewed 7570 times
grip.png
grip.png (82.67 KiB) Viewed 7570 times
Searle

Re: COMPOSITE_MULTIPLY ignores alpha channel of src

Post by Searle »

Same here, channels are constantly frustrating :-(

I' trying to word on seperate channels for 2 hours now with no success. Perhaps someone can help...

Code: Select all

$in = new Imagick("any-test-image.jpg");
$in_w= $in->getImageWidth();
$in_h= $in->getImageHeight();

$out_w= $in_w / 2;
$out_h= $in_h / 2;

$canvas= new Imagick();
$canvas->newImage($out_w, $out_h, new ImagickPixel("transparent"));
$canvas->setImageFormat("png");

$resized= $in->clone();
$resized->adaptiveResizeImage($out_w, $out_h);

$b= $resized->clone();
$b->separateImageChannel(Imagick::CHANNEL_BLUE);

$canvas->compositeImage($b, Imagick::COMPOSITE_OVER, 0, 0, Imagick::CHANNEL_BLUE);

header("Content-Type: image/png");
echo $canvas;
Channel is ignored. I tried a zillion workarounds, i'm out of ideas now. Ah well :-(

Ideas, someone?
Cheers,
Searle
Post Reply