Black line / linea nigra / черная линия

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
ghostmansd
Posts: 24
Joined: 2011-03-21T09:27:47-07:00
Authentication code: 8675308

Black line / linea nigra / черная линия

Post by ghostmansd »

Dear forum-users, is it possible to draw a black line, dividing an image? I need to draw a black line between pages to make Scan Talor recognize that file consists of two pages.
Debeo scriptvm, qvod cognoscit, si pagina duas paginas inclvdit. Si inclvdit, scriptvm has paginas una linea nigra dividit. Alteri applicationi interest, ut linea nigra sit.
Уважаемые форумчане, возможно ли нарисовать черную линию, разделяющую картинку на две части? Это необходимо для дальнейшей работы в Scan Tailor.
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Black line / linea nigra / черная линия

Post by fmw42 »

see -draw "line x1,y1 x2,y2" http://www.imagemagick.org/Usage/draw/#primitives

convert inputimage -stroke black -stroke-width 1 -draw "line x1,y1 x2,y2" resultimage
ghostmansd
Posts: 24
Joined: 2011-03-21T09:27:47-07:00
Authentication code: 8675308

Re: Black line / linea nigra / черная линия

Post by ghostmansd »

fmw42 wrote:see -draw "line x1,y1 x2,y2" http://www.imagemagick.org/Usage/draw/#primitives

convert inputimage -stroke black -stroke-width 1 -draw "line x1,y1 x2,y2" resultimage
Is it possible to get image size to know where to draw line? It seems that x1=1, y1=height/2, x2=width, y2=height/2.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Black line / linea nigra / черная линия

Post by fmw42 »

Is it possible to get image size to know where to draw line? It seems that x1=1, y1=height/2, x2=width, y2=height/2.
On Linux/Mac,

ww=`convert image -ping -format "%[fx:w-1]" info:`
hh=`convert image -ping -format "%[fx:h/2]" info:`
convert inputimage -stroke black -draw "line 0,$hh $ww,$hh" resultimage

see -string format and -fx escapes
http://www.imagemagick.org/script/escape.php
http://www.imagemagick.org/Usage/transform/#fx_escapes

I don't believe that -draw allows calculation within its arguments. But I could be wrong.

For Windows, see http://www.imagemagick.org/Usage/windows/
Last edited by fmw42 on 2011-03-27T15:34:52-07:00, edited 1 time in total.
ghostmansd
Posts: 24
Joined: 2011-03-21T09:27:47-07:00
Authentication code: 8675308

Re: Black line / linea nigra / черная линия

Post by ghostmansd »

I mean that what you've said. I've already decided this problem in a such way:
SZX=$(identify -format "%w" "$IMG")
SZY=$((SZY=$(identify -format "%h" "$IMG") / 2))
convert "$IMG" -white-threshold 75% -stroke black -strokewidth 10 -draw "line 1,$SZY $SZX,"$SZY"" "$IMG"

But your way is much easer. Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Black line / linea nigra / черная линия

Post by fmw42 »

You can also do:

coords=`convert inputimage -ping -format "0,%[fx:h/2] %[fx:w-1],%[fx:h/2]" info:`
convert inputimage -stroke black -draw "line $coords" resultimage

or


coords=$(convert inputimage -ping -format "0,%[fx:h/2] %[fx:w-1],%[fx:h/2]" info:)
convert inputimage -stroke black -draw "line $coords" resultimage
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Black line / linea nigra / черная линия

Post by anthony »

fmw42 wrote:
I don't believe that -draw allows calculation within its arguments. But I could be wrong.
Your not. At least not at this time. This may change, but at this time Percent escapes are not permitted by 'Draw'
arguments.

NOTE in the example image the center of the image is not the center of the book!

And finally you can draw beyond the image bounds, if that make things easier. Anything outsid ethe image proper is just ignored. As such you don't really have to worry about using %[fx:w-1] when %w will work just as well.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply