how to given the input coordinates

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
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

how to given the input coordinates

Post by sin »

hi,

can you please tell me how should i give the coordinates of a rectangle in a bash script??
Last edited by sin on 2011-07-30T01:54:09-07:00, edited 1 time in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: drawing a polygon

Post by Bonzo »

The points are the ends of the lines and with a polygon it is self closing so the last point has a line to the first point.

http://www.imagemagick.org/script/comma ... s.php#draw
The polyline and polygon primitives require three or more points to define their perimeters. A polyline is simply a polygon in which the final point is not stroked to the start point. When unfilled, this is a polygonal line. If the -stroke setting is none (the default), then a polyline is identical to a polygon.
So you have to calculate each point and can not say for example how many sides you want and the inscribing circle diamter etc.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: how to given the input coordinates

Post by anthony »

A rectangle is given as the positions of two diagonally oppisite corners. Any corners can be used.
See Draw Primatives
http://www.imagemagick.org/Usage/draw/#primitives

If you use a SVG path instead of a polyline or polygon, you can 'close' the path with a Z command.
See Draw SVG Path, moves. lines and closures.
http://www.imagemagick.org/Usage/draw/#lines
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: how to given the input coordinates

Post by sin »

how to crop that particular polygon using crop command??
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to given the input coordinates

Post by fmw42 »

sin wrote:how to crop that particular polygon using crop command??

see -trim or -crop

http://www.imagemagick.org/Usage/crop/#trim
http://www.imagemagick.org/Usage/crop/#crop

or explain in more detail what you are trying to do
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: how to given the input coordinates

Post by Bonzo »

Crop and trim can only work on rectangles and you want a poygon so I assume you will need to make a mask from the polygon.
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: how to given the input coordinates

Post by sin »

okay, thank you.

but the command for polygon/polyline is written in a .bat file and executed, it is not giving the correct picture whereas if it typed directly in the command line it is working.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to given the input coordinates

Post by fmw42 »

Bonzo,

Perhaps he wants the outside simply transparent rather than cropped. I will leave this one to you as he is on Windows.

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

Re: how to given the input coordinates

Post by anthony »

sin wrote:how to crop that particular polygon using crop command??
Two ways. image processing way as mentioned in to draw teh shape on a solid color canvas (transparent or colored) and trim. Note however that the acual bounds may be one pixel larger all around as -- lines have thickness and anti-alias smoothing

The other way is to get the maximum and minimum of all X and Y coordinates of the polygon. This is actually must faster when you have the coordinates, but may be slower if you don't know the coordinates. It also requires processin outside ImageMagick core library or commands, that is from the controlling API script/program.

Note the bound may not be correct if the shape is not a polygon of straight lines, but contains curves between the 'knot' or control coordinates. In that case a curve may extend beyond the min/max bounds of the input coordinates.


ASIDE: their is something I now consider a bug in drawing, in that the 'fill' will fill shapes as if it also includes a 1/2 pixel stroke width. This is historical, as typically users expect that when no 'stroke' border is included, but it is actually wrong.
See http://www.imagemagick.org/Usage/draw/#bounds
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: how to give the input coordinates

Post by sin »

echo "enter HEM_X3"
echo
set /p "E=>"
if %E% == End goto End
if %E% == end goto End
if %E% == "End" goto End
if %E% == "end" goto End

echo "enter HEM_Y3"
echo
set /p "F=>"
if %F% == End goto End
if %F% == end goto End
if %F% == "End" goto End
if %F% == "end" goto End

echo "enter HEM_X4"
echo
set /p "G=>"
if %G% == End goto End
if %G% == end goto End
if %G% == "End" goto End
if %G% == "end" goto End

echo "enter HEM_Y4"
echo
set /p "H=>"
if %H% == End goto End
if %H% == end goto End
if %H% == "End" goto End
if %H% == "end" goto End

convert -size 450x600 xc:black -fill white -stroke white -draw "polyline %G%,%H%,%E%,%F%,E+20,600,G-20,600" dwn.png


this is the .bat file i have written to get a polygon(using polyline). but I'm unable to get that :(
Post Reply