Right align text in area of image

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
Sjors

Right align text in area of image

Post by Sjors »

Hi,

i'm struggling with this: i'm building a table-like image.
All goes well, but i can't get this to work: i want to place some text at x,y: 10,10, but want to right align it in an area of 40x40 (that area starting at 10,10).
Why? because they are numbers.
When i draw text it's ok to place it at 10,10; it will by default be placed at 10,10 and thus be left-aligned. But i have some numbers which i want to 'right-align'. The next 'column' starts at X position 55, so i want to reserve some kind of imaginary region from x=10 to x=50 (to keep some 5 px margin to the next column) and draw the text from right to left at 10,50.

I found the geometry and gravity option and the region, but my trial and errors didn't give me any good results.

Michel
so what i want to accomplish is this (in code because it gives me the right font :):

Code: Select all

aaaa    12345      bbbbb
aaaa      345      bbbbb
aaaa        5      bbbbb

and not this
aaaa    12345      bbbbb
aaaa    345        bbbbb
aaaa    5          bbbbb
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Right align text in area of image

Post by anthony »

Best idea is to annotate the numbers into a 'column' image with gravity west.
When the column is complete you can then append columns, or overlay this column image onto the main image.


At this time IM does not make a distinction between using 'gravity' for placement,
and 'justification' (horizontally or vertically) of text and images at the position gravity determined. I have previously proposed that a 'justification' setting be created but have it default appropriately according to the current gravity setting when undefined.

This however has not been implemented. :-(


Note that while horizontal justification has 3 settings: left, center, right;
vertical justification would have 4: top, middle, baseline, bottom.
See http://www.imagemagick.org/Usage/bugs/f ... tification
for details of the proposal.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Sjors

Re: Right align text in area of image

Post by Sjors »

thanks very much for your reply.
Good to know i can stop searching the helpfiles :)
Post Reply