如何组合这些命令在 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
上面将根据图像的中心对图像进行方形裁剪。
所以我想做的就是结合这两个命令。
My aim:
该命令将图片作为输入,并基于图片的中心而不是基于图片的左上角对其进行圆形裁剪。
任何具有 IM 技能的人都可以向某人展示如何解决此问题吗?
Vesa
乌班图15.10
Update:
我尝试了下面 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 通道,然后将其合成到输入图像上。
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
现在,如果您打算裁剪many资源,我强烈建议创建一个掩码一次。根据需要重复使用面罩。
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)