【问题标题】:How to draw a image on top of a shape如何在形状上绘制图像
【发布时间】:2021-04-08 20:56:47
【问题描述】:

简化示例:

我确实创建了一个类似以下的圈子:

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

输入图像:

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

【问题讨论】:

  • 请包含您的输入图像in.png 或在尺寸/颜色方面具有代表性的东西。以及预期的输出图像。请注意magick convert ... 几乎总是错误的。它只是magick ... 没有convert
  • 我添加了一个完整的例子......我不知道你为什么需要那个 - 我的问题是一个语法问题,而不是关于脚本本身的帮助。我不知道你想对第二句话说什么 - magick convert 适合我,我应该只使用 magick 吗?
  • ImageMagick v7 引入了magick 作为命令的名称,以避免使用大量带有identifyconvertmogrifycompose 的命令命名空间, compare, stream 并避免与将文件系统转换为其他格式的 Windows convert 发生冲突。如果您使用magick convert ...,它会给您带来旧的 v6 行为,当您显然拥有 v7 时应该避免这种行为。我在这里解释了这一切stackoverflow.com/a/61208844/2836621

标签: imagemagick imagemagick-convert


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2020-10-24
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    • 1970-01-01
    • 2014-01-12
    相关资源
    最近更新 更多