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.

Recommended Answers

All 5 Replies

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

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!

Sweet as it worked thanks.

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:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.