3

So I want to create one large image of size 3600x2280 composed of three smaller images. The first should be resized to 1680x1050 and placed in the top left corner. The 2nd needs to be reiszed to 1920x1200 and placed immediately to the right of it (+1680 over). The 3rd image should be resized to 1920x1080 and placed on the bottom right (+1680+1200). The bottom left will just be blank/transparent.

I've tried various commands I've searched for online and think I'm getting somewhat close with something like the following for just two of the three images:

convert -define png:size=3600x2280 \( Photos/DSC05525-original.jpg -resize 1680x1050 \) -geometry +0+0 -composite \( Photos/Sydney-Loftus-Train-Station-original.jpg -resize 1920x1200 \) -geometry +1680+0 -extent 3600x2280 test.png

...but that places the 2nd image over the first (I think because it doesn't know to extend until the very end?). I've tried various combinations of -composite, -gravity and +repage, but can't seem to find a solution.

4

1 回答 1

6

有很多方法可以做到这一点。选择最适合您的思维方式的一种!我使用了这样的测试图像:

1.jpg => red
2.jpg => green (lime actually)
3.jpg => blue

方法一

convert -background none                               \
     1.jpg -resize 1680x1050!                          \
  \( 2.jpg -resize 1920x1200! \) +append               \
  \( 3.jpg -resize 1920x1080! -gravity east \) -append \
  result.png

在此处输入图像描述

这就是说... “让所有未上漆的区域保持透明。调整图像 1 的大小。调整图像 2 的大小并将其放在图像 1 的右侧(+append)。调整图像 3 的大小并将其向东对齐。将其附加到图像 1 和 2 的下方(-append)。

方法二

convert -background none                  \
  \( 2.jpg -resize 1920x1200! \)          \
  \( 3.jpg -resize 1920x1080! \) -append  \
  \( 1.jpg -resize 1680x1050! \) +swap +append  result.png

这就是说... “加载并调整图像 2 的大小。加载并调整图像 3 的大小。将图像 3放在图像2 的下方-append+swap第一个 ( ) 右侧的列表中的图像+append。”

方法三

convert -background none                                    \ 
    1.jpg -resize 1680x1050! -extent 3600x2280              \
 \( 2.jpg -resize 1920x1200! -geometry +1680 \)  -composite \
 \( 3.jpg -resize 1920x1080! -geometry +1680+1200 \) -composite result.png

这就是说...... “让任何未上漆的区域保持透明。加载图像 1 调整它的大小,然后将画布扩展到完整的输出大小以适应后续图像。加载图像 2,调整大小,定位并在画布上喷出。加载图像 3,调整大小并喷出画布上。”

方法四

只是为了好玩,这是一种完全不同的思考方式:

{ convert 1.jpg -resize 1680x1050! miff:- ;   \
  convert 2.jpg -resize 1920x1200! miff:- ;   \
  convert -size 1680x1 xc:none miff:- ;       \
  convert 3.jpg -resize 1920x1080! miff:- ; } | 
  montage -background none -geometry +0+0 -tile 2x2 miff:- result.png

这就是说...... “启动一个复合语句,它将加载和调整 4 个图像的大小,并将每个图像作为 MIFF(Magick 图像文件格式)发送到一个montage命令,该命令将它们全部放在2x2网格(-tile 2x2)中,它们之间没有空格(-geometry +0+0)。”

于 2016-03-03T11:39:44.210 回答