如何组合这些命令以在ImageMagick中实现循环裁剪?
所以这个命令有效:
convert -size 200x200 xc:none -fill samia.jpg -draw "circle 100,100 100,1" circle_thumb.png
Run Code Online (Sandbox Code Playgroud)
以上将拍摄照片并从中制作圆形裁剪但是裁剪将基于图片的左上角而不是图片的中心.
此命令也适用于裁剪:
convert *.jpg -resize 200x200^ -gravity Center -crop 200x200+0+0 +repage out.png
Run Code Online (Sandbox Code Playgroud)
以上将基于图像的中心进行图像的正方形裁剪.
所以我想要做的是结合两个命令.
我的目标:
一种命令,将图片作为输入,并根据图片的中心进行圆形裁剪,而不是基于图片的左上角.
任何有IM技能的人都可以向老兄展示如何解决这个问题?
VESA
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$
Run Code Online (Sandbox Code Playgroud)
emc*_*lle 11
这个问题被问了很多.
给定大于圆的图像.
convert -size 300x300 plasma: input.png
Run Code Online (Sandbox Code Playgroud)
我们可以绘制一个形状,将值转换为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
Run Code Online (Sandbox Code Playgroud)
现在,如果您计划裁剪许多资源,我强烈建议您创建一次掩码.根据需要重用掩码.
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
Run Code Online (Sandbox Code Playgroud)
不确定裁剪圆,但如果你想让除了中心圆之外的所有东西都透明,你可以这样做......
开始图片
提取一个半径为 80 的圆,使用:
magick start.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
Run Code Online (Sandbox Code Playgroud)