如何在形状上绘制图像

How to draw a image on top of a shape

简化示例:

我确实创建了一个如下的圈子:

magick convert -size 256x256 xc:none -fill #FFFFFF -draw "circle 128,128 256,128" +profile "icc" out.png

而且我会像下面这样转换给定的图像:

magick convert in.png -background none -gravity center -resize 181x181 +profile "icc" out.png

问题:

在我上面的示例中,我确实有以下“核心”功能:

如何在不将第一个图像保存到临时文件的情况下合并这些图像?我想创建一个 256x256 的输出图像,在该图像上绘制圆圈,然后在圆圈顶部绘制转换后的输入图像(居中)。

我目前的解决方案

创建 2 个不同的图像并将它们组合如下:

 magick convert -composite -gravity Center out1.png out2.png out.png

编辑 - 完整示例

PS 脚本如下所示:

$in = ".\in.png"
$out1 = ".\tmp1.png"
$out2 = ".\tmp2.png"
$out = ".\out.png"

// 1) create circle image
magick convert -size 256x256 xc:none -fill #FFFFFF -draw "circle 128,128 256,128" +profile "icc" PNG32:$out1

// 2) convert input image
magick convert $in -background none -gravity center -resize 181x181 +profile "icc" -colorspace Gray -fill "#E91FCB" -colorize 50 PNG32:$out2

// 3) combine circle + converted image
magick convert -composite -gravity Center $out1 $out2 PNG32:$out

// 4) delete temp. images
Remove-Item $out1
Remove-Item $out2

输入图像:

输出图像(不可见,但它有白色圆圈作为背景 + 否则为透明背景):

你可以像这样使用括号处理:

magick -size 256x256 xc:none -fill white -draw "circle 128,128 256,128" \( in.png -background none -gravity center -resize 181x181 -colorspace Gray -fill "#E91FCB" -colorize 50 \) -composite result.png

在 Windows 上,省略括号前的 \