ImageMagick 绘制带有特殊角的矩形

ImageMagick draw rectangle with special corners

你好,我想用 "special corners" 创建一个蒙版图像,我称它们为特别的,因为我真的不知道如何用英语称呼它们,这是我想要实现的:



我现在用的是

convert xc:black -size 300x300 -fill white -draw "roundrectangle 3,3,296,296,5,5"

但这给了我圆角。

提前感谢您的任何建议。

这是一个 link 页面,显示如何执行您想要的操作以及其他效果 https://www.imagemagick.org/Usage/thumbnails/#rounded

这是页面中的代码:

convert thumbnail.gif -alpha set  -compose DstOut \
      \( -size 20x15 xc:none -draw "polygon 0,0  0,14 19,0" \
         -write mpr:triangle  +delete \) \
      \( mpr:triangle             \) -gravity northwest -composite \
      \( mpr:triangle -flip       \) -gravity southwest -composite \
      \( mpr:triangle -flop       \) -gravity northeast -composite \
      \( mpr:triangle -rotate 180 \) -gravity southeast -composite \
      corner_cutoff.png

您应该查看示例,因为还有另一种方法可用于较小的图像。

这是一种方法。

convert -size 300x300 xc:none                   \
   -shave 10 -bordercolor black -border 10      \
   -fill black -draw "polyline 0,0 30,0 0,30"   \
   \( +clone -flip \) -gravity north -composite \
   \( +clone -flop \) -gravity south -composite -background white -flatten result.png

也就是说... "Draw a rectangle your full size and transparent, shave 10 pixels off all round and add a 10 pixel black border (easier than doing the maths and making a 280x280 and adding 10 on each side). Draw a triangle in the top-left. Copy the whole shape and flip it and draw it on top of the original. Copy the whole shape and flop it and draw it again on the original. Now make all the transparent areas white."

这是另一种方法 - 可能更简单一些。画出原来的正方形,然后复制,放大平方根(2)(即141%),加粗边框,旋转45度,合成到自身上。有点取决于你的大脑是如何工作的!

magick -size 300x300 xc:none -shave 10 -bordercolor black -border 10 \
  \( +clone -scale 142% -shave 30 -border 30 -rotate 45 \)  \
  -gravity center -composite -background white -flatten result.png