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

时间:2017-05-21 21:02:28

标签: 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 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

enter image description here

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-test_multi_child.png -background transparent -gravity center -resize 1473x755 \)  \
   -geometry +2000-50 \
   -composite iphone6plus-new.png

enter image description here

1 个答案:

答案 0 :(得分:1)

首先,settingsstrokewidthfill会一直存在,直到更改为止,所以不要一再重复。

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

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

+repage之后您可能需要-resize 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

enter image description here

相关问题