Page 1 of 1
CopyOpacity equivalent for php IMagick?
Posted: 2008-07-26T08:13:59-07:00
by Cadrach
Hi there,
I am new to ImageMagick but already fell in love with it
However I am currently stuck with a small issue:
I have found many command line examples of a mask used to specify the opacity zones of an image (like in this jigsaw example:
http://www.imagemagick.org/Usage/advanced/)
I would like to do the same using the php library, but I am stuck at the moment with:
Code: Select all
$img = new Imagick('myImage.png'); //Full image
$mask = new Imagick('mask.png'); //Black&White mask
$img->compositeImage($mask,Imagick::COMPOSITE_MULTIPLY,0,0,Imagick::CHANNEL_ALPHA);
This does not work as I would like since the black zones of the mask render black on the final image (instead of fully transparent). I have played with the COMPOSITE and CHANNEL constants to no avail.
Is there a way to do it?
Re: CopyOpacity equivalent for php IMagick?
Posted: 2008-07-26T11:06:03-07:00
by el_supremo
The copyopacity composite operator does not seem to be defined in Imagick. If you can use MagickWand for PHP, it is defined there.
Pete
Re: CopyOpacity equivalent for php IMagick?
Posted: 2008-07-28T21:00:57-07:00
by flemer
Cadrach,
I have upgraded ImageMagick to version 6.4.2, because I found that channel parameter is ignored in ImageMagick below 6.2.8. But I am still having the same issue.
I am trying to add a gradient mask to an image.
Alternatively, I have used a png image which has the gradient transparency (mask.png) and composited the image atop. At this manner the transparency of the fist image is inerited by the second.
Code: Select all
$canvas = new Imagick();
$canvas->newImage(760, 480, "transparent");
$canvas->setFormat("PNG");
$mask = new Imagick('mask.png');
$canvas->compositeImage($mask, imagick::COMPOSITE_COPY, 0, 0);
$image = new Imagick('imagem.png');
$canvas->compositeImage($image, imagick::COMPOSITE_ATOP, 0, 0);
$canvas->writeImage("final.png");
Does anybody knows a better way to do it?
Re: CopyOpacity equivalent for php IMagick?
Posted: 2008-07-28T23:42:37-07:00
by Cadrach
Thanks, I will try that and let you now, basically what I was trying to do was:
mask+image = final
(btw I was not able to do it using MagicDraw, DrawComposite only allows to compose a Draw with an image it seems)
Re: CopyOpacity equivalent for php IMagick?
Posted: 2008-07-29T00:59:13-07:00
by Cadrach
I used your code and your image files and the resulting image does not have any transparency. I checked my Imagick version using getVersion() and got 6.3.3. Where did you get the 6.4.2? I installed the latest PECL dll for php 5.2.5, and the 6.4.2 ImageMagick software, Q16 (I am under Windows XP)
Re: CopyOpacity equivalent for php IMagick?
Posted: 2008-07-29T15:44:04-07:00
by flemer
Cadrach,
Try the following code using the png image (mask.png) attached to this message. Note that mask.png must contain transparent pixels instead of black and white colors. The color of the pixels does not matter.
Code: Select all
$canvas = new Imagick();
$canvas->newImage(71, 123, "transparent");
$canvas->setFormat("PNG");
$mask = new Imagick('wall.png');
$canvas->compositeImage($mask, imagick::COMPOSITE_COPY, 0, 0);
$image = new Imagick('test.jpg');
$canvas->compositeImage($image, imagick::COMPOSITE_ATOP, 0, 0);
$canvas->writeImage("final.png");
Latest ImageMagick Release:
http://sourceforge.net/project/showfile ... p_id=24099
Re: CopyOpacity equivalent for php IMagick?
Posted: 2008-07-29T16:46:55-07:00
by mkoppanen
Imagick composite constants:
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_DEFAULT", OverCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_UNDEFINED", UndefinedCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_NO", NoCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_ADD", AddCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_ATOP", AtopCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_BLEND", BlendCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_BUMPMAP", BumpmapCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_CLEAR", ClearCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COLORBURN", ColorBurnCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COLORDODGE", ColorDodgeCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COLORIZE", ColorizeCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COPYBLACK", CopyBlackCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COPYBLUE", CopyBlueCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COPY", CopyCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COPYCYAN", CopyCyanCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COPYGREEN", CopyGreenCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COPYMAGENTA", CopyMagentaCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COPYOPACITY", CopyOpacityCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COPYRED", CopyRedCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_COPYYELLOW", CopyYellowCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_DARKEN", DarkenCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_DSTATOP", DstAtopCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_DST", DstCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_DSTIN", DstInCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_DSTOUT", DstOutCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_DSTOVER", DstOverCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_DIFFERENCE", DifferenceCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_DISPLACE", DisplaceCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_DISSOLVE", DissolveCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_EXCLUSION", ExclusionCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_HARDLIGHT", HardLightCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_HUE", HueCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_IN", InCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_LIGHTEN", LightenCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_LUMINIZE", LuminizeCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_MINUS", MinusCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_MODULATE", ModulateCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_MULTIPLY", MultiplyCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_OUT", OutCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_OVER", OverCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_OVERLAY", OverlayCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_PLUS", PlusCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_REPLACE", ReplaceCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_SATURATE", SaturateCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_SCREEN", ScreenCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_SOFTLIGHT", SoftLightCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_SRCATOP", SrcAtopCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_SRC", SrcCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_SRCIN", SrcInCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_SRCOUT", SrcOutCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_SRCOVER", SrcOverCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_SUBTRACT", SubtractCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_THRESHOLD", ThresholdCompositeOp );
IMAGICK_REGISTER_CONST_LONG( "COMPOSITE_XOR", XorCompositeOp );
Some documented better than the others..
Re: CopyOpacity equivalent for php IMagick?
Posted: 2008-07-29T18:04:15-07:00
by flemer
Koppanen, thank you very much.
The best way I found to add gradient transparency to an image:
Code: Select all
$mask = new Imagick('mask.png'); // gray scale mask (without transparency)
$mask->setImageMatte(false); // any alpha channel must be disabled
$image = new Imagick("imagem.jpg");
$image->setFormat("PNG");
/* When the overlay (source) image has no matte (alpha or matte) channel,
then COPYOPACITY operator will treat it as a simple grey-scale image mask. */
$image->compositeImage($mask, imagick::COMPOSITE_COPYOPACITY, 0, 0);
$image->writeImage("final.png");
Re: CopyOpacity equivalent for php IMagick?
Posted: 2008-07-30T01:37:51-07:00
by Cadrach
Yes, imagick::COMPOSITE_COPYOPACITY worked perfectly for me, thanks a lot!