PHP Tutorial - PHP imagettftext() function






Writes the given text into the image using TrueType fonts.

Syntax

PHP imagettftext() function has the following syntax.

array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )

Parameters

  • image - An image resource.
  • size - The font size.
  • angle - The angle in degrees, with 0 degrees being left-to-right reading text.
  • x - The coordinates given by x and y will define the basepoint of the first character.
  • y - The y-ordinate.
  • color - The color index.
  • fontfile - The path to the TrueType font.




Example


<?php//  ww w  .j av  a  2 s  . c  o  m
     $image = imagecreate(400,300);
     $blue = imagecolorallocate($image, 0, 0, 255);
     $white = ImageColorAllocate($image, 255,255,255);                                           
     imagettftext($image, 44, 15, 50, 200, $white,"ARIAL", "java2s.com");
     // Set the content-type
     header("content-type: image/png");
     imagepng($image);
     imagedestroy($image);

?>