I am trying to make a montage using imagemagick. I get it to work partially. I want to make a montage 2 columns by 2 rows. With 5px of padding between images, on a white background. When I use the following code the resulting image is twice as high and twice as wide as one image although only the first of four images appear in its correct size and spot, with white in the remaining three spots. All images are the same dimensions and same filetype.
<?php
header('Content-type: image/jpeg');
$loc1 = 'http://localhost:8888/gallery_edited/0116.jpg';
$loc2 = 'http://localhost:8888/gallery_edited/0115.jpg';
$loc3 = 'http://localhost:8888/gallery_edited/0114.jpg';
$loc4 = 'http://localhost:8888/gallery_edited/0113.jpg';
$image = new Imagick("$loc1 $loc2 $loc3 $loc4");
$image -> setFormat("jpg");
$image = $image -> montageImage(new ImagickDraw, '2x2', '600x400', 0, '0');
echo $image;
Use the Imagick::addImage to build the image stack with new instances of Imagick object.
<?php
$sources = array(
'red.png',
'green.png',
'blue.png',
'orange.png'
);
$stack = new Imagick();
foreach( $sources as $source ) {
$stack->addImage(new Imagick($source));
}
$montage = $stack->montageImage(new ImagickDraw(), '2x2', '500x300', 0, '0');
$montage->writeImage('out.png');
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