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

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
manit
Posts: 123
Joined: 2009-01-30T22:31:26-07:00

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

Post by manit » 2019-06-24T04:12:00-07:00

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.
Last edited by manit on 2019-06-24T21:51:31-07:00, edited 1 time in total.

snibgo
Posts: 12286
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2019-06-24T06:07:43-07:00

What version of IM, on what platform?

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

User avatar
GeeMack
Posts: 722
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

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

Post by GeeMack » 2019-06-24T10:52:33-07:00

manit wrote:
2019-06-24T04:12:00-07:00
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.
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 "\".

manit
Posts: 123
Joined: 2009-01-30T22:31:26-07:00

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

Post by manit » 2019-06-24T15:55:21-07:00

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.

manit
Posts: 123
Joined: 2009-01-30T22:31:26-07:00

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

Post by manit » 2019-06-24T16:04:13-07:00

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 .

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

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

Post by fmw42 » 2019-06-24T18:04:44-07:00

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.

manit
Posts: 123
Joined: 2009-01-30T22:31:26-07:00

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

Post by manit » 2019-06-24T20:33:51-07:00

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

Post Reply