How can I use imagemagick attributes in the draw rectangle command?

Deadly 提交于 2019-12-12 03:44:25

问题


I am trying to draw a rectangle across the full width of an image with convert [1]. I am trying to use ImageMagick Attributes to accomplish this.

The command I use is this:

convert ImageFile -fill black -stroke black -draw "rectangle 0,0 %[w],42" ImageFileNew

The Output I get is:

convert: NonconformingDrawingPrimitiveDefinition `rectangle' @ error/draw.c/DrawImage/3271.

With debug:

convert ImageFile -fill black -stroke black -draw "rectangle 0,0 %[w],42" ImageFileNew

I get:

2016-07-27T14:55:37+02:00 0:00.047 0.047u 7.0.2 Draw CONVERT[6660]: draw.c/DrawImage/1755/Draw
  begin draw-image
2016-07-27T14:55:37+02:00 0:00.047 0.047u 7.0.2 Draw CONVERT[6660]: draw.c/DrawImage/3207/Draw
  rectangle 0,0
2016-07-27T14:55:37+02:00 0:00.047 0.047u 7.0.2 Draw CONVERT[6660]: draw.c/DrawImage/3258/Draw
  end draw-image
CONVERT: NonconformingDrawingPrimitiveDefinition `rectangle' @ error/draw.c/DrawImage/3271.

I do not want to use a temporary file and I want to use this eventually after a trim repage. I would also like to replace the '42' with a formula if it is possible to use attributes in this command.

I guess the question is if this is supported( and if not then why the H not)?

[1] Version: ImageMagick 7.0.2-5 Q16 x64 2016-07-22 http://www.imagemagick.org


回答1:


I guess the question is if this is supported( and if not then why the H not)?

It should be supported, but I would suggest using the fx: protocol to calculate the values.

convert rose: -fill red \
       -draw 'rectangle 0 0 %[fx:w] %[fx:h]' \
       out_fill.png

I would guess you're seeing NonconformingDrawingPrimitiveDefinition as your starting to draw outside of the range of the authentic pixels. Remember that column / row index start at 0, and got to nth - 1.

convert rose: -fill red -stroke black -strokewidth 2 \
              -draw 'rectangle 0 0 %[fx:w-1] %[fx:h-1]' \
              out_stroke.png



来源:https://stackoverflow.com/questions/38614215/how-can-i-use-imagemagick-attributes-in-the-draw-rectangle-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!