Draw rectangle (non filled)

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
galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

Draw rectangle (non filled)

Post by galv » 2010-09-29T14:29:08-07:00

I want to draw a rectangle at given coordinates but not filled, just the outline. How can I do this?

el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Draw rectangle (non filled)

Post by el_supremo » 2010-09-29T14:43:55-07:00

Use a transparent fill. e.g.:

Code: Select all

convert logo: -fill none -stroke black -strokewidth 3 -draw "rectangle 10,10 630,470" logo_rect.png
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.

galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

Re: Draw rectangle (non filled)

Post by galv » 2010-09-29T15:29:33-07:00

Thank you for that. Is there a way to create more than one rectangles at different areas of the image (except from the obvious, calling convert more than once)? If yes, how?

User avatar
fmw42
Posts: 25668
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Draw rectangle (non filled)

Post by fmw42 » 2010-09-29T15:57:02-07:00

I believe you can call several rectangles with the same -draw (in the quotes), but for sure you can string draw commands together in the same command line.

see http://www.imagemagick.org/Usage/draw/
Last edited by fmw42 on 2010-09-29T19:27:16-07:00, edited 1 time in total.

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Draw rectangle (non filled)

Post by anthony » 2010-09-29T19:22:25-07:00

You can either use multiple -draw commands on the same image, OR repeat the rectangle (or other draw MVG commands) in the same draw command string.
http://www.imagemagick.org/Usage/draw/#intro

You can also write all your MVG draw commands into a file and simply read that file as a draw command string, or as an image in its own right!
http://www.imagemagick.org/Usage/draw/#reading
Anthony Thyssen wrote:There are lots of ways to skin a cat, and what method you use depends
on what you want that skin for, and how messy you like the results!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

Re: Draw rectangle (non filled)

Post by galv » 2010-10-06T07:04:10-07:00

Thanks for that, it worked.
Now I want to circle the same area so I'm using -draw circle with the same coordinates as region, but the result makes a circle larger than the area expected. Is there a calculation formula that I can use to bring it down to the correct region?

User avatar
fmw42
Posts: 25668
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Draw rectangle (non filled)

Post by fmw42 » 2010-10-06T13:49:02-07:00

galv wrote:Thanks for that, it worked.
Now I want to circle the same area so I'm using -draw circle with the same coordinates as region, but the result makes a circle larger than the area expected. Is there a calculation formula that I can use to bring it down to the correct region?
circle wants two points, the center and a point on the perimeter of the circle. So if you want a circle to pass through the corners of the rectangle, then you need to find the center of the rectangle and use one point at the corner. If you want the circle to be tangent to two sides or 4 sides if a square, then you need the center of the rectangle and the center of one side of the rectangle.

see http://www.imagemagick.org/Usage/draw/#circles

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Draw rectangle (non filled)

Post by anthony » 2010-10-06T21:07:25-07:00

You can also use arc which defines the 'circle' in terms of a bounding rectangle.
See Draw primatives
http://www.imagemagick.org/Usage/draw/#primitives
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply