【问题标题】:Image Magick - Cropping picture into circleImage Magick - 将图片裁剪成圆形
【发布时间】:2022-07-03 11:54:10
【问题描述】:

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

有谁知道如何使用 image magick 来实现这一点并遍历文件夹中的每个文件? - 谢谢

来源

期望的输出

【问题讨论】:

    标签: imagemagick imagemagick-convert


    【解决方案1】:

    制作一个 500x500 的图像,其中包含一个 400 像素的不透明圆圈 (mask.png)(对于您的所有输入,这当然是相同的图像):

    然后从来源:

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

    产量:

    【讨论】:

    • 这很棒,谢谢@xenoid。你知道我怎样才能让它遍历文件夹中的每个文件吗?它们都被命名为 1 到 100.png
    • 带有一个shell脚本。你的外壳是什么?
    • 我在 Windows 上,所以我猜只是一个批处理文件
    • 那超出了我的能力范围。
    • 别担心,谢谢你的帮助队友
    【解决方案2】:

    你可以在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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-12
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      • 1970-01-01
      • 2010-11-03
      • 1970-01-01
      相关资源
      最近更新 更多