Page 1 of 1

Calculate baseline of ttf?

Posted: 2009-06-20T01:11:09-07:00
by webunity
Next problem;

Let's say i generate a couple of headers using imagemagick.
I have three headers:
- "aaa" (nothing at the top and/or nothing at the bottom);
- "Hello" (spikes at the top from the "H" and "l");
- "geez" (spikes at the bottom from the "g");

If i want all 3 images to be the exact same height with e.g. font-size 12 and i want to align the bottom of the text at thesame Y position, how do i do that?

So i don't want this:
Image

But this:
Image

Any help on this one is appreciated.

P.s. i don't know the text i am going to create upfront and i don't know if the font i am going to use has either bigger "extensions" on the top or the bottom.

My best guess is that i have to generate an image with all characters which are "default" (like acemnosuvwxz) and calculate it based on that?

Re: Calculate baseline of ttf?

Posted: 2009-06-20T03:46:12-07:00
by webunity
found the solution (at least a workaround);
Generate the image twice;
1st time: append the chars (and find out the height of the image)
2nd time: don't append anything and find out the width of the image.

Finally; crop the image to the width (which you found the 2nd time) and the height (which you found the first time). Works perfect and no calculations required ;)

Re: Calculate baseline of ttf?

Posted: 2009-06-21T23:37:28-07:00
by anthony
for more direct alignment with different fonts look at
Creating Lines of Mixed Font Styles
http://www.imagemagick.org/Usage/text/#mixed_font_lines