Page 1 of 1

Single letter labels are not centered properly

Posted: 2011-10-29T19:24:11-07:00
by tabicat
Hi

This command displays a message centered inside a black rectangle.

Code: Select all

convert -size 30x30 -background '#00000080' -fill white -gravity center label:ABC test1.png
Image

However, if I tell it to write a single character, the alignment is off:

Code: Select all

convert -size 30x30 -background '#00000080' -fill white -gravity center label:A test2.png
Image

In this case, the letter "A" touches the top of the box. How can I fix this?

Re: Single letter labels are not centered properly

Posted: 2011-10-29T20:20:09-07:00
by anthony
The size of the label is designed to allow you to append labels together. That includes labels of lower case letters that have descenders!!! like 'y'

Also note that you do not have 'pointsize' set so the font is sized to 'best fit' the box, as best it can. It is also very font specific.

Best idea is the trim and enlarge the label to 'full center it.

Code: Select all

convert -size 30x30 -background 'none' -fill white -gravity center label:A \
       -trim +repage -gravity center -background '#00000080' -extent 30x30 test3.png
Note I only set background once as you are using a semi-transparent background!
If I didn't the 'overlay' performed by extent will result in a semi-transparency over a seni-transparency whcih does not look right. Using opaque backgrounds, or full-transparency (above) do not have these problems.