how to draw a rectangle with 100% width?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
roach

how to draw a rectangle with 100% width?

Post by roach »

I'm trying to draw a rectangle on an existing image, such that the rectangle is flush with the top of the image, and covers 100% of the width of the image.

Something like:

convert inputFile.jpg -fill white -stroke white -draw "rectangle 0,0 100%,20" output.jpg

Of course that doesn't work, but can anyone tell me how I might accomplish this?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: how to draw a rectangle with 100% width?

Post by Bonzo »

You can use fx to find the width of the image; this would have to be saved into a variable then use the variable in the command that you have.
roach

Re: how to draw a rectangle with 100% width?

Post by roach »

Nevermind. I ended up using a combination of -chop and -splice instead. Worked for what I needed.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: how to draw a rectangle with 100% width?

Post by anthony »

NOTE the rectangle size is also effecting not just by the pixel dimentions given, but also the stroke width used.

One example of generating a rectangle to a specific image was exampled in IM Examples, Thumbnails, Border with Rounded Corner

Part of that example is enlarging the final image size slightly so as to minimise the amount of image that gets covered up by the added border.

However the -chop or -shave with a -splice or -border method is probably easiest.
See cutting and bordering...
http://www.imagemagick.org/Usage/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply