PHP imagettftext() function

In this chapter you will learn:

  1. Description for PHP imagettftext() function
  2. Syntax for PHP imagettftext() function
  3. Parameters for PHP imagettftext() function
  4. Example - Draw text

Description

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/*j  a v 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);

?>

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP Predefined Math Constants
Home » PHP Tutorial » PHP Image Functions
PHP imagearc() function
PHP imagecreate() function
PHP imagecreatetruecolor () function
PHP imageellipse() function
PHP imagefilledarc() function
PHP imageline() function
PHP imagepolygon() function
PHP imagerectangle() function
PHP imagesetpixel() function
PHP imagettftext() function