Page 1 of 1

[SOLVED] drawing line using relative coordinate like 'bottom left'

Posted: 2019-06-24T04:12:00-07:00
by manit
hi,
I am writing a script that takes a x,y coordinate from a text file then draws a circle around that position.
It also picks up label from the same text file for that x,y coordinate and appends it at the bottom of image.
Now, I want to draw a line from that x,y position to bottom of image.
My problem is that '-draw line' operator needs absolute pixel coordinates.
It would be better if the text I add at the bottom gets enclosed in rectangle.
Currently my script executes following command
convert bkup_dwas.png -fill none -strokewidth 2 -stroke yellow -draw "circle 258,356 258,361" bkup_dwas.png
convert bkup_dwas.png -background white -fill yellow -pointsize 24 label:"some text" -gravity south -append bkup_dwas.png
Please note that my image vertical dimension changes every time text gets added at the bottom.

Re: drawing line using relative coordinate like 'bottom left'

Posted: 2019-06-24T06:07:43-07:00
by snibgo
What version of IM, on what platform?

I suggest you use IM v7, with "magick". Then your parameters to circle can be "%[fx:...]" expressions.

Re: drawing line using relative coordinate like 'bottom left'

Posted: 2019-06-24T10:52:33-07:00
by GeeMack
manit wrote: 2019-06-24T04:12:00-07:00I am writing a script that takes a x,y coordinate from a text file then draws a circle around that position.
It also picks up label from the same text file for that x,y coordinate and appends it at the bottom of image.
Now, I want to draw a line from that x,y position to bottom of image.
As snibgo mentioned above, if you can use IM version 7 you'll be able to use FX expressions as arguments within your draw operation. But...

If the line needs to go straight to the bottom and not at an angle, you can start a line at the top coordinates, the center of the circle, and draw that line way past the bottom of the image. A command like this would combine your circle drawing command and your command that adds the label, and also draws a line from the center of the circle straight down and beyond the bottom of the input image...

Code: Select all

convert bkup_dwas1.png -fill none -strokewidth 2 -stroke yellow ^
   -draw "circle 258,356 258,361 line 258,356 258,100000" ^
   -pointsize 24 label:"some text" -gravity south -append bkup_dwas2.png
That starts by reading the input image and drawing the circle at the given coordinates.

Then it draws a line starting at the coordinates for the center of the circle. For the other end of the line you can use the given X coordinate and a Y coordinate far greater than the height your input is likely to be.

Next the label is created and appended to the bottom. Then all that's left is writing the output file.

That command is in Windows command line syntax. To use it on *nix you'll have to escape the parentheses with backslashes "\(...\)" and replace those continued line carets "^" with backslashes "\".

Re: drawing line using relative coordinate like 'bottom left'

Posted: 2019-06-24T15:55:21-07:00
by manit
I am using
$ convert --version
Version: ImageMagick 6.8.9-9 Q16 x86_64 2018-09-28 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib
on 64 bit ubuntu OS .
I will try that addition of 'line x,y x,10000' .
thanks.

Re: drawing line using relative coordinate like 'bottom left'

Posted: 2019-06-24T16:04:13-07:00
by manit
That draws a vertical line.
Combining both was a good idea too.
Now, if somehow I could get text enclosed in rectangle while adding to image then it will be clear that which vertical line is meant for which text .

Re: drawing line using relative coordinate like 'bottom left'

Posted: 2019-06-24T18:04:44-07:00
by fmw42
Before you append the text image at the bottom of the main image just draw a thin border around the text image using -bordercolor ... -border. See https://imagemagick.org/Usage/crop/#border.

I answered here, but in the future, please do not double post the same question.

Re: drawing line using relative coordinate like 'bottom left'

Posted: 2019-06-24T20:33:51-07:00
by manit
This adds bottom border so that vertical line touches it
convert dwas.png -fill none -strokewidth 2 -stroke red -draw "circle 110,105 110,115 line 110,105 110,10000" -gravity south -background red -splice 0x2 \( -background white -pointsize 24 label:"text" -gravity south \) -append what.png