Example
function appendImages()
{
$images = [
[
"../public/images/lories/IMG_1599_480.jpg",
"../public/images/lories/IMG_2561_480.jpg"
],
[
"../public/images/lories/IMG_2837_480.jpg",
"../public/images/lories/IMG_4023_480.jpg"
]
];
$canvas = new Imagick();
foreach ($images as $imageRow) {
$rowImagick = new Imagick();
$rowImagick->setBackgroundColor('gray');
foreach ($imageRow as $image_path) {
$imagick = new Imagick(realpath($image_path));
$imagick->setImageBackgroundColor("gray");
$imagick->resizeimage(200, 200, \Imagick::FILTER_LANCZOS, 1.0, true);
$rowImagick->addImage($imagick);
}
$rowImagick->resetIterator();
//Add the images horizontally.
$combinedRow = $rowImagick->appendImages(false);
$canvas->addImage($combinedRow);
}
$canvas->resetIterator();
//Add the images vertically.
$finalimage = $canvas->appendImages(true);
$finalimage->setImageFormat('jpg');
header("Content-Type: image/jpeg");
echo $finalimage->getImageBlob();
}