如何解决如何在形状上绘制图像
简化示例:
我确实创建了一个如下所示的圆:
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" +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" +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 上,省略括号前的 \
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。