0

简化示例:

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

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

问题:

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

  • -size 256x256 xc:none -fill #FFFFFF -draw "circle 128,128 256,128" +profile "icc"
  • in.png -background none -gravity center -extent 181x181 +profile "icc"

如何在不将第一个图像保存到临时文件的情况下合并这些图像?我想创建一个 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

输入图像:

在此处输入图像描述

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

在此处输入图像描述

4

1 回答 1

2

您可以像这样使用带括号的处理:

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 上,省略\前面的括号。

于 2021-04-08T12:56:47.297 回答