Confused on the -draw option

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
Scott.Prog

Confused on the -draw option

Post by Scott.Prog »

Okay, I've been staring at this and trying various parameters and can't make heads or tails of how or why this:

Code: Select all

    convert -size 100x60 xc:skyblue -fill white -stroke black \
            -draw "circle 50,30 40,10"          draw_circle.gif
Generates this:

Image

I can certainly see how the starting point of the draw operation is centered at 50,30. When I find the center of the image, it is at 50,30. I can even make quasi- sense of the 40 value being that the left and right edges of the circle are approximately 20 pixels (1/2) left and right, at 20, 70 (if that assumption is even valid).

The number 10 is throwing me. The top edge of the circle is *approximately* at y-axis 10 but that use doesn't make sense to me to have the second parameter (10) be an axis position when the first parameter (40) looks to be an offset value.

Feel to flame my n00bery, tell me to read the manual (which I have), insult my family lineage, etc. but I just don't get it. Explain please? Thanks in advance.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Confused on the -draw option

Post by Bonzo »

From memory :
Center point of the circle from top left corner in X = 50
Center point of the circle from top left corner in Y = 30

Start point of the circle from top left corner in X = 40
Start point of the circle from top left corner in Y = 10
Scott.Prog

Re: Confused on the -draw option

Post by Scott.Prog »

Thank you for responding. That is also what I would have assumed and would be intuitive. However, the top left corner of the image is at 30,10, not 40,10. Here is a the same graphic with a bounding box drawn centered on the circle and the corner positions annotated:

Image

What am I missing?
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Confused on the -draw option

Post by el_supremo »

"circle 50,30 40,10"
The first coordinate is that of the centre of the circle. The second is the coordinate of a point on the circumference.

Pete
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Confused on the -draw option

Post by Bonzo »

The second 2 numbers are where the cicle is drawn from; I would have written it like:

Code: Select all

"circle 50,30 50,10"
This would give you a circle with the center at X50 Y30 and the radius would be 30 - 10 = 20

Th radius in the original example would have been 22.36 ?
Scott.Prog

Re: Confused on the -draw option

Post by Scott.Prog »

Bonzo wrote: The second 2 numbers are where the cicle is drawn from; I would have written it like:

Code: Select all

"circle 50,30 50,10"
This would give you a circle with the center at X50 Y30 and the radius would be 30 - 10 = 20


Alright, I suppose that helps some. There are really only three data points in use then? The location of the center point of the circle and a radius value? What, if any, is the purpose of the 3rd value, in your example "circle 50,30 50,10"?

The example I had provided came from Anthony's examples page:

http://www.imagemagick.org/Usage/draw/#intro
Scott.Prog

Re: Confused on the -draw option

Post by Scott.Prog »

The property must have some effect. Changing the original example from 40 to 50 results in a smaller circle:

Orig Image "circle 50,30 40,10"
New Image "circle 50,30 50,10"
Last edited by Scott.Prog on 2007-02-10T12:32:25-07:00, edited 1 time in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Confused on the -draw option

Post by Bonzo »

The point on the circumferance ( as el_supremo says ) needs fixing in the X and Y direction.
Center point of the circle from top left corner in X = 50
Center point of the circle from top left corner in Y = 30

Start point of the circle from top left corner in X = 40
Start point of the circle from top left corner in Y = 10

I normaly use the same position in the X for both the X coordinates as it simplys things and just set the radius in the Y.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Confused on the -draw option

Post by Bonzo »

Perhaps I have it the wrong way around and the second set of numbers is the distance from the center of the circle to a point on the circumferance - I have only used circle once before !

That means: circle 50,30 40,10 has a rad of 22.36
and circle: 50,30 50,10 has a rad of 10

That looks better; its a long time since I went to school but you use Pythagoras' Theorem
Scott.Prog

Re: Confused on the -draw option

Post by Scott.Prog »

Ok, I finally understand. Sometimes you look at a problem too long and get lost in a particular track of thinking. This works more like a real world compass for drawing circles. You place the compass point at a specific point on the page which becomes your first two values, the center point of the circle. After spreading the calipers, the point on the page where you place the pencil point becomes the two second values which are not offset from the center point and do not represent a radius value, per se. Instead, they are absolute coordinates from which ImageMagick calculates the radius value and draws the circle.

Counterintuitive at first and perhaps contrary to the "bounding box" principal of Photoshop and others but very usable once understanding the principals.

Thanks to all who responded as you got me out of my thinking rut. Your input is appreciated.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Confused on the -draw option

Post by anthony »

I am glad you have all worked it out...

If you want to define a circle in terms of a bounding box use ellipse. If you want it in terms of a one point to another point use the 'path' circle method.
All three are given in IM examples, drawing page.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply