Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell imagemagick:如何在“绘制矩形”命令中使用%[fx:…]运算符?_Shell_Image Processing_Terminal_Imagemagick_Imagemagick Convert - Fatal编程技术网

Shell imagemagick:如何在“绘制矩形”命令中使用%[fx:…]运算符?

Shell imagemagick:如何在“绘制矩形”命令中使用%[fx:…]运算符?,shell,image-processing,terminal,imagemagick,imagemagick-convert,Shell,Image Processing,Terminal,Imagemagick,Imagemagick Convert,我可以在图像上绘制一个红色矩形: convert original.png-填充红色-绘制“矩形10,20 150,40”结果.png 150,40是右下角坐标。但是,如果我在其中使用%[fx:…]操作符,如下所示: convert original.png-填充红色-绘制“矩形10,20%[fx:w-30],40”结果.png %[fx:w-30]应该计算到图像的宽度减去30 但是,我得到了一个错误: convert:non-configurance绘图原语定义'rectangle'@erro

我可以在图像上绘制一个红色矩形:

convert original.png-填充红色-绘制“矩形10,20 150,40”结果.png

150,40是右下角坐标。但是,如果我在其中使用
%[fx:…]
操作符,如下所示:

convert original.png-填充红色-绘制“矩形10,20%[fx:w-30],40”结果.png

%[fx:w-30]
应该计算到图像的宽度减去30

但是,我得到了一个错误:

convert:non-configurance绘图原语定义'rectangle'@error/draw.c/DrawImage/4227

我也尝试了单引号(')而不是双引号(“),但这没有什么区别

我的imagemagick版本是7.0.7-36


我做错了什么?在上述示例中使用
%[fx:…]
运算符的正确方法是什么?

多亏了@GeeMack,解决方案是:使用
magick
而不是
convert
,因此它变成:


magick original.png-填充红色-绘制“矩形10,20%[fx:w-30],40”结果。png

如果您仍在ImageMagick 6上,可以使用
identify
命令输出格式化字符串,然后在
convert
命令中使用该字符串。使用shell语法,可以表示如下:

convert original.png -fill red -draw "$(identify -format 'rectangle 10,20 %[fx:w-30],40' original.png)" result.png

对于ImageMagick 7,你应该使用“magick”而不是“convert”。@GeeMack,谢谢,以前从未听说过。我的convert版本是7.0.7-36,但显然,
convert
magick
之间有区别。无论如何,它是有效的,谢谢!在IM 7中使用convert通常会调用IM 6。IM 6不支持%[fx…]大多数命令中的行计算。如果您设置到magick的符号链接,则可以在IM7中使用convert。