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

后端 未结 4 1724
清酒与你
清酒与你 2021-02-08 09:28

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 w

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-08 09:55

    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... :-)

提交回复
热议问题