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

imagemagick, php

Solution

Here is a commandline to do the image appending due to the extended requirements, where the right picture should be offset by 200 pixels from the left edge, regardless of the (smaller) width of the left image:

 convert                          \
   -background '#FFF9E3'          \
    xc:none -resize 200x1\!       \
    right+narrow.png -append      \
    left+wider.png                \
   -gravity south                 \
   +append                        \
   -crop '400x +0+1'              \
   +repage                        \
    result.png

The part `xc:none -resize 200x1\!` creates a 1 pixel high, 200 pixels long line and vertically appends the smaller (right) image to it.

To this intermediate result the horizontally appending of the wider (left) image happens. We would now have a 401x100 picture with a maybe ugly line of transparent pixels on top.

That's why we shave off this top pixel line with the `-crop` function.

You should be able to translate that into PHP yourself... :-)

Problem

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.

Original source

Related problems