What is the function used to create text on an image in PHP and how can the font be changed?

To create text on an image in PHP, you can use the `imagettftext()` function. This function allows you to specify the font, size, angle, coordinates, and color of the text to be placed on the image. To change the font, you need to specify the path to the TrueType font file (.ttf) that you want to use.

// Create a new image
$image = imagecreatefromjpeg('image.jpg');

// Set the font path
$font = 'arial.ttf';

// Set the text color
$textColor = imagecolorallocate($image, 255, 255, 255);

// Add text to the image
imagettftext($image, 20, 0, 10, 50, $textColor, $font, 'Hello World');

// Output the image
header('Content-Type: image/jpeg');
imagejpeg($image);

// Free up memory
imagedestroy($image);