0

Hello Community,
I have spent almost an hour looking for a solution to combine several pictures side-by-side but can't seem to find anything.

I want to be able to get a dozen pictures (.png) and place them to the right of the previous picture then combine them as one (.png) picture.

3
Contributors
5
Replies
35
Views
3 Years
Discussion Span
Last Post by cereal
0

In Photoshop you can add the widths and the take height as that of tallest when creating your canvas - then insert the images and save

1

Try with appendImages(), like in this example:

<?php

$list = array(
    './i/001.jpg',
    './i/002.jpg',
    './i/003.jpg',
    './i/004.jpg'
    );

# first image to start Imagick()
$im = new Imagick($list[0]);
$ilist = array();

# loop the others
for($i = 1; $i < count($list); $i++)
{
    $ilist[$i] = new Imagick($list[$i]);
    $im->addImage($ilist[$i]);
}

$im->resetIterator();
$combined = $im->appendImages(false);
$combined->setImageFormat("png");
header('Content-Type: image/png');
echo $combined;

To create the list you can use glob() instead of an hardcoded array:

$list = glob('./i/*.jpg');

Docs: http://php.net/manual/en/imagick.appendimages.php

Bye!

Edited by cereal

0

For completeness, you can also use the montageImage() method:

<?php

$list = array(
    './i/001.jpg',
    './i/002.jpg',
    './i/003.jpg',
    './i/004.jpg'
    );

$im     = new Imagick($list);
$draw   = new ImagickDraw();

$result = $im->montageImage($draw, "4x1+0+0", '300x200+0+0', imagick::MONTAGEMODE_CONCATENATE, '15x15+0+0');
$result->setImageFormat("png");

header('Content-Type: image/png');
echo $result;

This method will create thumbnails as defined in the third argument: 300x200+0+0. The difference is that the appendImage() method, of the previous example, will output original sizes.

The second argument, instead, allows you to specify the columns and rows, so if you want them all in horizontal line set: 4x1+0+0.

Documentation:

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.