0

I am placing text on an image using GD. GD places text on the baseline. I am using ImageTTFBBox to get the height of the box and am able to calculate where the bottom of the text is. But since gd uses the baseline to place text. How can I figure out where the baseline is? The text and placement and size is all dynamic.

I am using giddyup 52px font and placing it in the top left corner, no margins/padding, for example. I get the text height using ImageTTFBBox and it is 54px. So I place the text at 0,54px using imagettftext().

The text is going to be about 12px too far down, because the baseline of the text box is at 54 px not the bottom of the text which ends up being at about 66px.

Thank you for your time,

Todd

maddogandnoriko
  • 980
  • 2
  • 13
  • 31
  • I'm not sure whether it's possible using the GD library, but you need to get the descender value of the font's metrics. Imagick provides the queryFontMetrics method for this, but I'm not aware of a pure GD solution. – daiscog Jun 12 '12 at 14:51
  • Thanks for the comment, at least I know the term I need (descender value and font metrics), maybe that will help me out a bit. – maddogandnoriko Jun 12 '12 at 17:46
  • GD gives you informations about actual ascent and descent for a specific text and font. See the solution at http://stackoverflow.com/questions/6737419/php-imagettftext-baseline-workaround/15001168#15001168 – Marco Jacovone Feb 22 '13 at 00:48

0 Answers0