【发布时间】:2022-07-03 11:54:10
【问题描述】:
我有 100 多个 500x500 的 png 文件,我试图在图像中心裁剪一个 400x400 的圆圈并将其保存到一个单独的 png 中,保持 500x500。下面的例子
有谁知道如何使用 image magick 来实现这一点并遍历文件夹中的每个文件? - 谢谢
来源
期望的输出
【问题讨论】:
标签: imagemagick imagemagick-convert
我有 100 多个 500x500 的 png 文件,我试图在图像中心裁剪一个 400x400 的圆圈并将其保存到一个单独的 png 中,保持 500x500。下面的例子
有谁知道如何使用 image magick 来实现这一点并遍历文件夹中的每个文件? - 谢谢
来源
期望的输出
【问题讨论】:
标签: imagemagick imagemagick-convert
你可以在How can I combine these commands to achieve circular crop in 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
【讨论】: