Image Magick - 将图片裁剪成圆形

问题描述 投票:0回答:4

我有 100 多个 png 文件,都是 500x500,我试图在 400x400 图像的中心裁剪一个圆圈,并将其保存到一个单独的 png 中,同时保持 500x500。下面的例子

有谁知道如何使用图像魔术来实现这一点并运行文件夹中的每个文件? - 谢谢

来源

期望的输出

imagemagick imagemagick-convert
4个回答
1
投票

制作一个 500x500 的图像,其中有一个 400 像素的不透明圆圈 (

mask.png
)(这当然是所有输入的相同图像):

然后来自消息来源:

convert source.png mask.png -compose copy-opacity -composite result.png

产量:


0
投票

您可以在我如何组合这些命令以在 ImageMagick 中实现循环裁剪中找到答案?

magick convert input.jpg -gravity center ( -size 480x480 xc:black -fill white -draw "circle 240 240 240 0" -alpha copy ) -compose copyopacity -composite output.png
magick input.jpg ( +clone -threshold 101% -fill white -draw "circle %[fx:int(w/2)],%[fx:int(h/2)] %[fx:int(w/2)],%[fx:int(h)]" ) -channel-fx "| gray=>alpha" output.png
magick input.jpg ( +clone -threshold 101% -fill white -draw "roundRectangle 0,0 %[fx:int(w)],%[fx:int(h)] 50,50" ) -channel-fx "| gray=>alpha" output.png
magick input.jpg ( +clone -threshold 101% -fill white -draw "roundRectangle %[fx:int((w-h)/2)],0 %[fx:int((h+w)/2)],%[fx:int(h)] 50,50" ) -channel-fx "| gray=>alpha" -trim output.png

0
投票

您可以使用 mogrify 处理文件夹中的每个 (png) 图像。假设 Imagemagick 6. 只需将目录更改为文件夹并将路径添加到 mask.png 图像,它不应该在该目录中。

mogrify -alpha set -draw "image copy_opacity 0,0 0,0 'mask.png'" *.png

0
投票

magick input.jpg ( +clone -threshold 101% -fill white -draw "roundRectangle 0,0 %[fx:int(w)],%[fx:int(h)] 50,50" ) -channel-fx “|灰色=>alpha”输出.png 不能在 Windows 中工作,magick V7。 “灰色”不被识别为内部或外部命令, 可运行的程序或批处理文件。

这可以克服吗?

© www.soinside.com 2019 - 2024. All rights reserved.