如何合并这些命令以在ImageMagick中实现圆形裁剪?
因此,此命令有效:
convert -size 200x200 xc:none -fill samia.jpg -draw "circle 100,100 100,1" circle_thumb.png
上面将拍摄一张图片,并从中制作出圆形的裁剪,但是裁剪将基于图片的左上角而不是图片的中心。
此命令也可用于裁剪:
convert *.jpg -resize 200x200^ -gravity Center -crop 200x200+0+0 +repage out.png
上面将基于图像的中心对图像进行方形裁剪。
所以我想做的就是结合这两个命令。
我的目标:
将图片作为输入并根据图片的中心而不是图片的左上角对其进行圆形裁剪的命令。
任何具有IM技能的人都可以向哥们展示如何解决此问题?
维萨
Ubuntu 15.10
更新:
我在下面尝试了Mark Setchell的解决方案,但收到以下错误消息:
axx@axx-VPCEA3S1E:~/Desktop/circular-crop$ magick samia.png \( +clone -threshold 101% -fill white -draw 'circle %[fx:int(w/2)],%[fx:int(h/2)] %[fx:int(w/2)],%[fx:80+int(h/2)]' \) -channel-fx '| gray=>alpha' circle.png
magick: no decode delegate for this image format `PNG' @ error/constitute.c/ReadImage/509.
magick: no image to apply a property "%w" @ warning/property.c/GetMagickPropertyLetter/2561.
magick: unknown image property "%w" @ warning/property.c/InterpretImageProperties/3499.
magick: no image to apply a property "%h" @ warning/property.c/GetMagickPropertyLetter/2449.
magick: unknown image property "%h" @ warning/property.c/InterpretImageProperties/3499.
magick: no image to apply a property "%m" @ warning/property.c/GetMagickPropertyLetter/2480.
magick: unknown image property "%m" @ warning/property.c/InterpretImageProperties/3499.
axx@axx-VPCEA3S1E:~/Desktop/circular-crop$
最佳答案
这个问题被问了很多。
给定大于圆的图像。
convert -size 300x300 plasma: input.png
我们可以绘制形状,将值转换为alpha channel ,然后在输入图像上进行构图。
convert input.png \
-gravity Center \
\( -size 200x200 \
xc:Black \
-fill White \
-draw 'circle 100 100 100 1' \
-alpha Copy \
\) -compose CopyOpacity -composite \
-trim output.png
现在,如果您打算种植许多资源,我强烈建议您创建一个 mask 。根据需要重新使用 mask 。
convert -size 200x200 xc:Black -fill White -draw 'circle 100 100 100 1' -alpha Copy mask.png
for f in $(ls *.jpg)
do
convert $f -gravity Center mask.png -compose CopyOpacity -composite -trim ${f}_output.png
done