The php Function Imagettftext
The php function imagettftext can be used to add text to an existing image, or to create a new one from scratch. The function uses TrueType fonts, and is part of the GD library, which must be compiled into your version of PHP in order to work with it. Most commercial web hosts provide GD as a standard feature of their web servers.
Getting text to fit precisely into an image can be tricky, especially if you are using a rotation, or a font that has not been optimised for this purpose. The php function imagettfbbox() is designed to make this easier, by returning the coordinates of a bounding box around your text, in x and y formats.
The main function for generating text images, however, is imagettftext(). This takes eight parameters in total: the image resource to be worked upon, font size in points, angle to draw at, x co-ordinate, y co-ordinate, text to write, and the name of the font to use.
The y co-ordinate works in a similar way to the x co-ordinate in imagefilledarc(), but is anti-clockwise (so 15 degrees gives text that slants upwards rather than left-to-right). The text to write will be any UTF-8 sequence of letters. The colour to use for the text is set with the imagecolorallocate() function, and can be any colour that exists in your image. Alternatively, if you know the font name in advance, you can use a direct path to it by providing the fontfile() argument instead.