如何使用 ImageMagick/GraphicsMagick 像三角形一样连接 3 个图像

How to concatenate 3 images like a triangle using ImageMagick/GraphicsMagick

我有三张图片,a.jpg, b.jpg, c.jpg。

我想连接它们,使它们看起来像下面这样:

我想用一个命令来完成。没有生成 tmp 文件。 我如何使用 IM/GM.

来做到这一点

假设所有图片的尺寸都正确,这可能是最简单的:

convert -size 10x10 green.png xc:white black.png -append xc:white red.png -reverse +append result.png

也就是说……"make the size of the little spacers 10x10. Load the green image, then make a white spacer, then load the black image and append them together vertically. Make another white spacer. Load the red image. Reverse the columns of images so the most recently added red column is at the left instead of the right, append the images side-by-side."

我是这样做的(从右侧开始),因为 GraphicsMagick 不提供括号。


如果图像的大小还不合适,您会看到更像这样的东西 - 仍然是一个命令:

convert -size 10x10                 \
    \( green.png -resize somehow \) \
    xc:white                        \
    \( black.png -resize somehow \) \
    -append                         \
    xc:white                        \
    \( red.png -resize somehow   \) \
    -reverse +append result.png

ImageMagick 中的另一种方法是使用 smush 而不是附加。 Smush 允许偏移量。

创建图像:

convert -size 250x250 xc:green green.png
convert -size 250x250 xc:black black.png
convert -size 250x510 xc:red red.png

现在合并它们:

convert -background white red.png \
\( green.png black.png -smush 10 \) \
+smush 10 \
result.png

在 ImageMagick 中执行此操作的另一种方法是将 3 个图像合成到白色背景图像的适当角落。

创建图像:

convert -size 250x250 xc:green green.png
convert -size 250x250 xc:black black.png
convert -size 250x510 xc:red red.png

进程:

convert -size 510x510 xc:white \
red.png -gravity northwest -composite \
green.png -gravity northeast -composite \
black.png -gravity southeast -composite \
result.png