ImageMagick,是否将特定位置/大小的图像插入到较大的图像中?

ImageMagick,是否将特定位置/大小的图像插入到较大的图像中?,imagemagick,imagemagick.net,Imagemagick,Imagemagick.net,我首先画了一个带列的宽透明图像,效果很好 convert -size 5568x1920 xc:none iphone6plus.png convert iphone6plus.png -strokewidth 0 -fill lightgray -draw "rectangle 1080,0 1121,1920 " iphone6plus.png convert iphone6plus.png -strokewidth 0 -fill lightgray -draw "rectangle 22

我首先画了一个带列的宽透明图像,效果很好

convert -size 5568x1920 xc:none iphone6plus.png
convert iphone6plus.png -strokewidth 0 -fill lightgray -draw "rectangle 1080,0 1121,1920 " iphone6plus.png
convert iphone6plus.png -strokewidth 0 -fill lightgray -draw "rectangle 2202,0 2243,1920 " iphone6plus.png
convert iphone6plus.png -strokewidth 0 -fill lightgray -draw "rectangle 3324,0 3365,1920 " iphone6plus.png
convert iphone6plus.png -strokewidth 0 -fill lightgray -draw "rectangle 4446,0 4487,1920 " iphone6plus.png
convert /en-US/iPhone6Plus-main_start_multi_child.png \
-rotate -2 \
iphone6plus-new.png
然后我旋转另一个图像,同样工作正常

convert -size 5568x1920 xc:none iphone6plus.png
convert iphone6plus.png -strokewidth 0 -fill lightgray -draw "rectangle 1080,0 1121,1920 " iphone6plus.png
convert iphone6plus.png -strokewidth 0 -fill lightgray -draw "rectangle 2202,0 2243,1920 " iphone6plus.png
convert iphone6plus.png -strokewidth 0 -fill lightgray -draw "rectangle 3324,0 3365,1920 " iphone6plus.png
convert iphone6plus.png -strokewidth 0 -fill lightgray -draw "rectangle 4446,0 4487,1920 " iphone6plus.png
convert /en-US/iPhone6Plus-main_start_multi_child.png \
-rotate -2 \
iphone6plus-new.png
但是,我尝试将第二个(旋转图像)插入到第一个图像的特定位置/大小。我遇到了问题,我尝试了几种方法,最近的一种方法似乎覆盖了源图像

convert iphone6plus.png \
 -geometry 40x40+5+10  \
 -composite \
iphone6plus-new.png
我应该用什么

我还应该如何提高这个操作的速度

编辑:问题如下所示

convert -size 5568x1920 xc:none -strokewidth 0 -fill lightgray \
   -draw "rectangle 1080,0 1121,1920 "  \
   -draw "rectangle 2202,0 2243,1920 "  \
   -draw "rectangle 3324,0 3365,1920 "  \
   -draw "rectangle 4446,0 4487,1920 "  \
   \( iPhone6Plus-main_start_multi_child.png -background transparent -rotate -2 -gravity center -resize 1473x755 \)  \
   -geometry -190-50 \
   \( iPhone6Plus-test_multi_child.png -background transparent -gravity center -resize 1473x755 \)  \
   -geometry +2000-50 \
   -composite iphone6plus-new.png


首先,
设置
行程宽度
填充
在更改之前一直保持不变,因此不要重复这些设置

其次,只需创建一次背景并不断添加,而不是保存并关闭,然后在下一行重新打开

convert -size 5568x1920 xc:none -strokewidth 0 -fill lightgray \
   -draw "rectangle 1080,0 1121,1920 "  \
   -draw "rectangle 2202,0 2243,1920 "  \
   -draw "rectangle 3324,0 3365,1920 "  \
   -draw "rectangle 4446,0 4487,1920 "    basic.png
现在,加载需要旋转的新图像,并在括号内对其应用旋转,以使其余图像不受影响,然后将其合成到背景上:

convert -size 5568x1920 xc:none -strokewidth 0 -fill lightgray \
   -draw "rectangle 1080,0 1121,1920 "  \
   -draw "rectangle 2202,0 2243,1920 "  \
   -draw "rectangle 3324,0 3365,1920 "  \
   -draw "rectangle 4446,0 4487,1920 "  \
   \( SomeOtherImage.png -rotate -2 -resize AxB \)  \
   -geometry +X+Y -composite result.png
-调整AxB的大小后,可能需要
+重新分页

更新的答案

这可能更接近你需要的吗

#!/bin/bash
convert -size 5568x1920 xc:none -strokewidth 0 -fill lightgray -background transparent -gravity center \
   -draw "rectangle 1080,0 1121,1920"  \
   -draw "rectangle 2202,0 2243,1920"  \
   -draw "rectangle 3324,0 3365,1920"  \
   -draw "rectangle 4446,0 4487,1920"  \
   \( xc:blue[1024x768] -rotate -2 -resize 1473x755 \) -geometry -190-50 -composite \
   \( xc:red[1024x768] -resize 1473x755 \)  -geometry +2000-50 -composite result.png

旋转图像时,其大小和边界框会发生变化。当您尝试在背景图像上合成它时,它是相对于背景图像的左上角合成边界框的左上角。避免此类问题的最佳方法是使用-gravity center和-geometry+X+Y以及相对于背景图像中心的X和Y值。这样,合成将覆盖图像的中心定位在距背景图像中心的所需偏移点处。因此,将-gravity center添加到Marks命令和相应的center rel。X和Y.@fmw42谢谢,但这并不能完全解决我的第二个图像问题。如果我注释掉第一个旋转图像,如Marks answer中所示,则第二个图像将显示在第一个图像的位置。我在我的问题中添加了一个关于的编辑。你能更清楚地解释一下问题是什么吗?我现在还不太明白。我所能看到的只是两段新代码和两幅新图像,但我不知道哪个是错的,哪个是对的,以及它应该是什么样子……这就对它进行了排序:)添加复合物是有意义的,它是黑色的。干杯