Page 1 of 1
How to center text?
Posted: 2012-07-02T23:36:16-07:00
by agriz
How to center text according to this image on those particular boxes?
Thanks
Re: How to center text?
Posted: 2012-07-03T00:03:37-07:00
by anthony
How were the boxes made? Just in a previously given image, or drawn?
Are they static or can they move about? Do they vary in size?
What do you want to know for? -- their may be alternative solutions.
Basically what do we have to work with?
Re: How to center text?
Posted: 2012-07-03T00:11:29-07:00
by agriz
Assuming that the boxes are static in size, and which is already fixed with the original image, how can we center the text?
[if we can't create similar box and composite on the original image, how can we center the text?]
Re: How to center text?
Posted: 2012-07-03T00:14:06-07:00
by agriz
I can use -gravity and -annotate but what can i do if the text size is not same all the time?
Re: How to center text?
Posted: 2012-07-03T10:25:27-07:00
by fmw42
always use offset coordinates relative to the center of the image to the center of the boxes using -gravity center
Re: How to center text?
Posted: 2012-07-03T11:49:46-07:00
by agriz
can you just give any example? i didn't know how to give offset coordinates ...
Re: How to center text?
Posted: 2012-07-03T12:32:13-07:00
by Bonzo
-gravity center will find the center of the image and you can offset it with -geometry +10+10
If you are using -annotate you can offset it in the -annotate command -annotate +10+10 "text"
Re: How to center text?
Posted: 2012-07-03T12:36:04-07:00
by agriz
Yes, But how can i center dynamic text with different number of characters?
ex : "This is funny", "booo", "hon", ...
Re: How to center text?
Posted: 2012-07-03T12:42:29-07:00
by Bonzo
If it was me I would write the text into a box with a transparent backgound ( caption or label ) then find the size of the box bounding the text and do some calculations on placing the text in the correct place.
You do not say how you are running the code but you may have to use fx for the calculations if you have no other way of doing the calculations.
Re: How to center text?
Posted: 2012-07-03T12:45:50-07:00
by agriz
Yes, It is good idea. I will try the transparent background method and i will let you know.
It will work perfectly, I guess

Re: How to center text?
Posted: 2012-07-03T12:49:52-07:00
by Bonzo
Using caption or label the bounding box size will change that is why I said you may need to use fx etc. to calculate the position.
If you always use a box the same size and center the text in the box the position will be the same every time when compositing.
Re: How to center text?
Posted: 2012-07-03T16:03:05-07:00
by fmw42
Yes, But how can i center dynamic text with different number of characters?
ex : "This is funny", "booo", "hon", ...
If you write your text using -annotate with -gravity center, it will center the text at the offset location. At least that is my understanding. Thus it does not matter how long the text is, so long as it does not exceed your box size.
The same for label: and caption: if you create those images in center justified mode and then use -gravity center and -geometry to place them at the center of your box. The only computations from fx: would be to compute the box coordinates center relative and not top left relative.
Re: How to center text?
Posted: 2012-07-03T21:28:00-07:00
by anthony
agriz wrote:I can use -gravity and -annotate but what can i do if the text size is not same all the time?
I would generate a gravity centered 'caption:' of the appropriate size (with or without a pointsize), and then layer that caption on the background image.
http://www.imagemagick.org/Usage/text/#caption