[英]imagemagick: how to use the %[fx:…] operator in draw rectangle command?
I can do this to draw a red rectangle on an image:我可以这样做在图像上绘制一个红色矩形:
convert original.png -fill red -draw "rectangle 10,20 150,40" result.png
The 150,40 is the right bottom coordinate. 150,40 是右下角坐标。 However if I use the %[fx:...]
operator in there, like so:但是,如果我在那里使用%[fx:...]
运算符,如下所示:
convert original.png -fill red -draw "rectangle 10,20 %[fx:w-30],40" result.png
The %[fx:w-30]
is supposed to evalute to the image's width minus 30. %[fx:w-30]
应该计算图像的宽度减去 30。
However I'm getting an error:但是我收到一个错误:
convert: non-conforming drawing primitive definition `rectangle' @ error/draw.c/DrawImage/4227.转换:不符合绘图基元定义`矩形'@error/draw.c/DrawImage/4227。
I have also tried single quotes (') instead of double (") but that made no difference.我也试过单引号 (') 而不是双引号 (") 但这没什么区别。
My imagemagick version is 7.0.7-36.我的 imagemagick 版本是 7.0.7-36。
What am I doing wrong?我究竟做错了什么? What's the correct way of using the %[fx:...]
operator in the above example?在上面的例子中使用%[fx:...]
运算符的正确方法是什么?
感谢@GeeMack 解决方案是:使用magick
而不是convert
,所以它变成:
magick original.png -fill red -draw "rectangle 10,20 %[fx:w-30],40" result.png
If you're still on ImageMagick 6, you can use the identify
command to output a formatted string and then use that in the convert
command.如果您仍在使用 ImageMagick 6,则可以使用identify
命令输出格式化的字符串,然后在convert
命令中使用它。 Using shell syntax, this can be expressed as follows:使用 shell 语法,这可以表示如下:
convert original.png -fill red -draw "$(identify -format 'rectangle 10,20 %[fx:w-30],40' original.png)" result.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.