使用 ImageMagick 在一个正方形中组合多个图像并调整其大小
Combine and resize multiple images in a square using ImageMagick
所以我想创建一张由三张小图片组成的 3600x2280 大图片。第一个应调整为 1680x1050 并放置在左上角。第二个需要调整为 1920x1200 并立即放置在它的右侧(+1680 以上)。第三张图片应调整为 1920x1080 并放置在右下角 (+1680+1200)。左下角将只是 blank/transparent。
我已经尝试了我在网上搜索的各种命令,我认为对于三张图片中的两张,我已经有点接近下面的内容了:
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
...但这会将第二张图片放在第一张图片上(我想是因为它不知道要延伸到最后?)。我已经尝试了 -composite、-gravity 和 +repage 的各种组合,但似乎找不到解决方案。
有很多方法可以做到这一点。选择最符合您的思维方式的一种!我使用了这样的测试图像:
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
也就是说……"Leave all unpainted areas transparent. Resize image 1. Resize image 2 and place it to the right of image 1 (+append
). Resize image 3 and align it East. Append that underneath images 1 and 2 (-append
)."
方法二
convert -background none \
\( 2.jpg -resize 1920x1200! \) \
\( 3.jpg -resize 1920x1080! \) -append \
\( 1.jpg -resize 1680x1050! \) +swap +append result.png
也就是说……"Load and resize image 2. Load and resize image 3. Place image 3 underneath image 2 (-append
). Load and resize image 1. Place image 1 before (+swap
) image 2 in the image list. Now append the second image in the list to the right of the first (+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
也就是说……"Leave any unpainted areas transparent. Load image 1 resize it then extend the canvas to the full output size to accommodate subsequent images. Load image 2, resize, position and splat onto canvas. Load image 3, resize and splat onto canvas."
方法四
只是为了好玩,这是一种完全不同的思考方式:
{ 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
也就是说……"Start a compound statement that will load and resize 4 images and send each of them as a MIFF (Magick Image File Format) to a montage
command that will put them all together in 2x2
grid (-tile 2x2
) with no spaces between them (-geometry +0+0
)."
所以我想创建一张由三张小图片组成的 3600x2280 大图片。第一个应调整为 1680x1050 并放置在左上角。第二个需要调整为 1920x1200 并立即放置在它的右侧(+1680 以上)。第三张图片应调整为 1920x1080 并放置在右下角 (+1680+1200)。左下角将只是 blank/transparent。
我已经尝试了我在网上搜索的各种命令,我认为对于三张图片中的两张,我已经有点接近下面的内容了:
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
...但这会将第二张图片放在第一张图片上(我想是因为它不知道要延伸到最后?)。我已经尝试了 -composite、-gravity 和 +repage 的各种组合,但似乎找不到解决方案。
有很多方法可以做到这一点。选择最符合您的思维方式的一种!我使用了这样的测试图像:
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
也就是说……"Leave all unpainted areas transparent. Resize image 1. Resize image 2 and place it to the right of image 1 (+append
). Resize image 3 and align it East. Append that underneath images 1 and 2 (-append
)."
方法二
convert -background none \
\( 2.jpg -resize 1920x1200! \) \
\( 3.jpg -resize 1920x1080! \) -append \
\( 1.jpg -resize 1680x1050! \) +swap +append result.png
也就是说……"Load and resize image 2. Load and resize image 3. Place image 3 underneath image 2 (-append
). Load and resize image 1. Place image 1 before (+swap
) image 2 in the image list. Now append the second image in the list to the right of the first (+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
也就是说……"Leave any unpainted areas transparent. Load image 1 resize it then extend the canvas to the full output size to accommodate subsequent images. Load image 2, resize, position and splat onto canvas. Load image 3, resize and splat onto canvas."
方法四
只是为了好玩,这是一种完全不同的思考方式:
{ 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
也就是说……"Start a compound statement that will load and resize 4 images and send each of them as a MIFF (Magick Image File Format) to a montage
command that will put them all together in 2x2
grid (-tile 2x2
) with no spaces between them (-geometry +0+0
)."