Defining alpha

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
ophiuci

Defining alpha

Post by ophiuci »

Hello,
I am trying to use MagickWand to combine two images where one image contains color and the other contains a b/w alpha image. I want to output a transparent png. Is there currently a way to accomplish this? Any help would be appreciated.

Thanks.
ophiuci

Re: Defining alpha

Post by ophiuci »

Here is the code I ended up with. Does exactly what I needed:

Code: Select all

  $mgk_alpha=NewMagickWand();
  MagickReadImage($mgk_alpha,'alpha.jpg');
	MagickNegateImage($mgk_alpha, true);
	MagickSetImageType($mgk_alpha, MW_GrayscaleType);

	$mgk_color=NewMagickWand();
	MagickReadImage($mgk_color,'color.jpg');
	MagickSetImageFormat($mgk_color, "PNG");

	$result = MagickCompositeImage($mgk_color, $mgk_alpha, MW_CopyOpacityCompositeOp, 0, 0);

	header('Content-Type: image/png');
	MagickEchoImageBlob( $mgk_color );
Solution found from: http://www.imagemagick.org/Usage/compose/#copyopacity
mrBlaQ
Posts: 17
Joined: 2008-02-05T12:19:00-07:00

Solved

Post by mrBlaQ »

wait, I'm replying to the wrong thread....
Post Reply