Imagemagick 如何在形状上绘制图像

Imagemagick 如何在形状上绘制图像,imagemagick,imagemagick-convert,Imagemagick,Imagemagick Convert,简化示例: 我确实创建了一个如下所示的循环: 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.p

简化示例:

我确实创建了一个如下所示的循环:

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
 magick convert -composite -gravity Center out1.png out2.png out.png
$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 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
 magick convert -composite -gravity Center out1.png out2.png out.png
$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
问题:

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

  • -尺寸256x256 xc:none-填充#FFFFFF-绘制“圆圈128128 256128”+剖面图“icc”
  • in.png-背景无-重心-范围181x181+剖面“icc”
如何在不将第一个图像保存到临时文件的情况下合并这些图像?我想创建一个256x256输出图像,将圆绘制到此图像,然后在圆的顶部(居中)绘制转换后的输入图像

我当前的解决方案

创建两个不同的图像,并按如下方式组合它们:

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
 magick convert -composite -gravity Center out1.png out2.png out.png
$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
编辑-完整示例

PS脚本如下所示:

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
 magick convert -composite -gravity Center out1.png out2.png out.png
$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上,省略括号前的
\

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

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

请将您的输入图像
包含在.png
或具有代表性的大小/颜色中。以及预期的输出图像。请注意,
magick convert…
几乎总是错误的。它只是
magick…
而没有
convert
。。。我不知道你为什么需要它-我的问题是一个语法问题,而不是关于脚本本身的帮助。我不知道你想对第二句话说什么-
magick convert
对我有效,我应该只使用
magick
吗?ImageMagick v7引入了
magick
作为命令名,以避免使用大量带有
标识
的命令命名空间,
转换
mogrify
组合
比较
并避免与将文件系统转换为其他格式的Windows
转换
冲突。如果您使用
magick convert…
它将为您提供旧的v6行为,当您明确使用v7时,您应该避免这些行为。我在这里解释了所有内容,请在.png
中包含您的输入图像
,或者在大小/颜色方面具有代表性的内容。以及预期的输出图像。请注意,
magick convert…
几乎总是错误的。它只是
magick…
而没有
convert
。。。我不知道你为什么需要它-我的问题是一个语法问题,而不是关于脚本本身的帮助。我不知道你想对第二句话说什么-
magick convert
对我有效,我应该只使用
magick
吗?ImageMagick v7引入了
magick
作为命令名,以避免使用大量带有
标识
的命令命名空间,
转换
mogrify
组合
比较
并避免与将文件系统转换为其他格式的Windows
转换
冲突。如果您使用
magick convert…
它将为您提供旧的v6行为,当您明确使用v7时,您应该避免这些行为。我在这里都解释过了