1

I am using imagettftext function to write text on my image but the problem is when i set x,y postion to 0,0 in it does write text on top left of the image .

Is there any way to make my point of origin top left ??

Shaun
  • 2,313
  • 7
  • 36
  • 43

1 Answers1

0

From the PHP Manual:

The coordinates given by x and y will define the basepoint of the first character (roughly the lower-left corner of the character). This is different from the imagestring(), where x and y define the upper-left corner of the first character. For example, "top left" is 0, 0.

So if you want the origin point on top left you can use imagestring() or you can sum the letter height to the y point of the imagettftext() function.

To get the height of the letter you can use imagettfbbox() function:

$bbox = imagettfbbox ( $size , $angle , $fontfile , $text );
$y_offset = abs($bbox[7] - $bbox[1]);
imagettftext ( $image , $size , $angle , $x , $y + $y_offset , $color , $fontfile , $text );
user2013861
  • 43
  • 1
  • 6