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.
source share