1

I have a weird issue with TTF and PHP GD 2.x.

I have a size 45px TTF at top position 100. The top of the text is perfect align with a line (in the image).

BUT if I change the size of the font, the text is no longer align with the line.

At size 20px I need to subtract 5 to the top value of the text and if the font is size 300px I need to add 56 to the top value to get the perfect alignment.

And the worse if I change font (another TTF) it's the same but with different number.

Did I miss something. Why I need to change the top value of the text depending of the size of it and why the number I have for one font is not the same as another one?????

And if all that is normal. How can I get a formula to always get the text align on the line.

Here some number....

Font 1 . size 20 = top 95, size 45 = top 100, size 300 = top 156.
Font 2 . size 20 = top 91, size 193 = top 100, size 300 = top 105. 

I'm not so good in math....sad

Thanks

Bill

lebill
  • 1,293
  • 2
  • 8
  • 9

1 Answers1

0

You'd be better off using Imagick, which lets you query the font's metrics. You probably need either the font's x-height, or cap height value, which you can't get from GD.

Once you've got those values, then you can properly calculate the vertical offset you need to line everything up.

Marc B
  • 356,200
  • 43
  • 426
  • 500