I've been having some trouble generating an image with the Imagick PHP extension. Everything works fine, except my following "montage" has a white background and therefore I cannot overlay it on top of something else. How can I generate 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!!
Imagick is a PHP extension to create and modify images using the ImageMagick library. There is also a version of Imagick available for HHVM. Although the two extensions are mostly compatible in their API, and they both call the ImageMagick library, the two extensions are completely separate code-bases.
To enable Imagick for your website, go to your Site Tools -> Dev -> PHP Manager. Click the PHP Extensions tab and find the entry for the “imagick” extension in the list that appears. Then click the Change value button (pencil icon), select the On radio button for Status and save the changes.
ImageMagick is a PHP utility, a command line tool for image manipulation. For further details, see this. Imagick is an API or a class that performs the function same as ImageMagick. It provides numerous functions for image manipulation in PHP.
I know this is an old question, but I found another way to do this using Imagick's montageImage function. After you create your Imagick object you must declare the background as transparent like this:
$Icons->setBackgroundColor( new ImagickPixel('transparent') );
Once that is set, 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");
Then you can add the new montage image to your composite image making sure to use the predefined Imagick composite constant COMPOSITE_ATOP or your desired constant(s) like this:
$Canvas->compositeImage($Montage, imagick::COMPOSITE_ATOP, 5, 5);
Just ran across this question and decided to post another solution in case someone else wants another way to do this without a manual loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With