简体   繁体   中英

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

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

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

out_fill

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

中风

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM