Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine 2 images side by side into 1 with ImageMagick (PHP)

I think this is an easy one.

I have 2 Pictures/JPGs and i want them to merge into one picture where the 2 are side by side.

So i have pic [A] and pic [B] and I want to get pic [AB] (side by side).

Both images have same width and height. In this case width=200px and height=300px. But the 2nd Image should appear on position 200,0 .. also when imagewidth is smaller than 200px (200px is maxwidth)

This is what I've tried (php):

exec($IMAGEMAGICK_PATH."composite picA.jpg -geometry +200+0 picB.jpg picAB.jpg");

I also tried the same with "-size 400x300" after "composite" but nothing happens. Problem is that the image picA.jpg is moved 200px and merged into picB.jpg, but the width of picAB.jpg is the same as picB.jpg is.

I'm also not sure if "-geometry" is the correct command.

like image 426
John Doe Smith Avatar asked Aug 22 '12 15:08

John Doe Smith


1 Answers

Maybe you'll find the montage method easier to understand (this is probably what you had in mind when you tried it with composite -- but that one is for overlapping images, not for side-by-side montage...)

montage                 \
  -background '#FFF9E3' \
  -geometry 200\!x\>    \
  -gravity west         \
   right+narrow.jpg     \
   left+wider.jpg       \
   result.jpg
like image 63
Kurt Pfeifle Avatar answered Oct 19 '22 02:10

Kurt Pfeifle