我知道这是一个老问题,但我找到了另一种使用 Imagick 的 montageImage 函数的方法。创建 Imagick 对象后,您必须将背景声明为透明,如下所示:
$Icons->setBackgroundColor( new ImagickPixel('transparent') );
设置完成后,您可以通过 montageImage 运行该对象,这将创建一个具有透明背景的 montageImage:
$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.