Imagick PHP Extension - installation assistance?

I'm having trouble creating an image with the PHP Imagick extension. Everything works just fine, except that my next โ€œmontageโ€ has a white background, and therefore I cannot overlay it on top of something else. How can I create a montage with a transparent background?

$Montage = $Icons->montageImage(new imagickdraw(), "3x2+0+0", "34x34+3+3", imagick::MONTAGEMODE_UNFRAME, "0x0+0+0"); $Canvas->compositeImage($Montage, $Montage->getImageCompose(), 5, 5); 

Thanks!!

+4
source share
2 answers

I had the same problem and found that the MagickWand C API, which supports imagick), does not support the mounting option.

I finished it manually this way:

 // Add them to an array of Imagick objects, instead of using addImage(). $images = new Array(); // Make a transparent canvas. $target = new Imagick(); $target->newImage($width, $height * count(images), 'none'); $i = 0; foreach ($images as $image) { $target->compositeImage($image, imagick::COMPOSITE_COPY, 0, $height * $i++); } 
+3
source

I know this is an old question, but I found another way to do this using the Imagick montageImage function. After creating the Imagick object, you should declare the background transparent as follows:

$Icons->setBackgroundColor( new ImagickPixel('transparent') );

Once this is installed, you can run the object through montageImage, which will create a montageImage with a transparent background:

 $Montage = $Icons->montageImage(new imagickdraw(), "3x2+0+0", "34x34+3+3", imagick::MONTAGEMODE_UNFRAME, "0x0+0+0"); 

You can then add a new mount image to the composite image, making sure that you use the predefined Imagick COMPOSITE_ATOP composite constant or your desired constant (s) as follows:

$Canvas->compositeImage($Montage, imagick::COMPOSITE_ATOP, 5, 5);

Just stumbled upon this question and decided to post another solution if someone wants a different way to do it without a manual loop.

+3
source

Source: https://habr.com/ru/post/1309705/


All Articles