Page 1 of 1

COMPOSITE_MULTIPLY ignores alpha channel of src

Posted: 2010-07-09T16:49:41-07:00
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 7571 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' );

Re: COMPOSITE_MULTIPLY ignores alpha channel of src

Posted: 2010-11-17T08:18:56-07:00
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