使用ImageMagick(PHP)将2张图像并排放入1中 [英] Combine 2 images side by side into 1 with ImageMagick (PHP)

查看:109
本文介绍了使用ImageMagick(PHP)将2张图像并排放入1中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这很简单。

我有2张图片/ JPG,我希望它们合并成一张并排2张的图片。

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

所以我有图片[A]和图片[B],我想获得图片[AB](并排)。

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

两幅图像的宽度和高度相同。在这种情况下,宽度= 200px,高度= 300px。 但第二张图像应出现在位置200,0 ..当图像宽度小于200像素(200像素是最大宽度)时

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)

这是什么我试过(php):

This is what I've tried (php):

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

在复合之后我也尝试使用-size 400x300,但没有任何反应。
问题是图像picA.jpg被移动200px并合并到picB.jpg,但picAB.jpg的宽度与picB.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.

我也不确定-geometry是否是正确的命令。

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

推荐答案

这是一个命令行要做由于扩展要求而附加的图像,其中右图片应偏离左边缘200像素,而不管左图像的(较小)宽度:

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

部件 xc:none -resize 200x1 \!创建1像素高,200像素长的线,并垂直附加较小(右)的图像。

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

对于这个中间结果,会发生更宽(左)图像的水平附加。我们现在有一张401x100的照片,顶部有一条可能很难看的透明像素。

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.

这就是为什么我们用去掉这个顶部像素线的原因-crop function。

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

你应该能够自己将它翻译成PHP ...: - )

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

这篇关于使用ImageMagick(PHP)将2张图像并排放入1中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆