### composite, parenthesis, -gravity problems

Posted:

**2017-06-29T09:03:21-07:00**The script below places pre-prepared rectangles containing numbers 27-0

along a line (scale50.png) of given length at approximately(1.) equal

intervals. It works OK.

###################### script ####################################

imgconvert -size 727x20 xc:'white' scale50.png

while [ i -le 27 ]

do

j=$(echo "($i*26.8 + 1.5)/1" | bc) # (...)/1 for nearest integer

n='27-i'

imgconvert scale50.png rect"$n".png -geometry +"$j"+3 -composite scale50.png

i=i+1

done

################################################################

However, to avoid making separate rectangles I tried replacing

rect"$n".png above with:

\( -size 20x14 xc:'none' \

-fill 'black' -font Arial-Bold -pointsize 13 \

-gravity center -annotate 0 "$n" -trim \) \

It almost worked, except the first number was positioned in

the centre of the target line (scale50.png), the other numbers

followed on at equal distances from that centre.

It seems the gravity option centered the first number relative

to the line and the geometry was ignored, but only for the first

cycle.

Note 1. Many attempts have been made to position the numbers close

to being equidistant.

Relying on '-gravity center' is not consistent, numbers can be

1 or 2, sometimes more pixels off-center which accumulates over

a longish list (eg if appending boxes containing successive `centered' numbers).

An attempt, not yet achieved, would be to trim the numbers, find

their widths and position them using calculations based on their (hopefully),

well defined widths.

along a line (scale50.png) of given length at approximately(1.) equal

intervals. It works OK.

###################### script ####################################

imgconvert -size 727x20 xc:'white' scale50.png

while [ i -le 27 ]

do

j=$(echo "($i*26.8 + 1.5)/1" | bc) # (...)/1 for nearest integer

n='27-i'

imgconvert scale50.png rect"$n".png -geometry +"$j"+3 -composite scale50.png

i=i+1

done

################################################################

However, to avoid making separate rectangles I tried replacing

rect"$n".png above with:

\( -size 20x14 xc:'none' \

-fill 'black' -font Arial-Bold -pointsize 13 \

-gravity center -annotate 0 "$n" -trim \) \

It almost worked, except the first number was positioned in

the centre of the target line (scale50.png), the other numbers

followed on at equal distances from that centre.

It seems the gravity option centered the first number relative

to the line and the geometry was ignored, but only for the first

cycle.

Note 1. Many attempts have been made to position the numbers close

to being equidistant.

Relying on '-gravity center' is not consistent, numbers can be

1 or 2, sometimes more pixels off-center which accumulates over

a longish list (eg if appending boxes containing successive `centered' numbers).

An attempt, not yet achieved, would be to trim the numbers, find

their widths and position them using calculations based on their (hopefully),

well defined widths.