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.
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:
$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?
Last edited by Cadrach on 2008-07-26T11:07:18-07:00, edited 1 time in total.
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.
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)
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.
$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");