How can PHP load a system font to write text on an image?
To load a system font to write text on an image in PHP, you can use the `imagettftext()` function. This function allows you to specify the font file path, size, angle, coordinates, and text to be written on the image. Make sure to provide the correct font file path and ensure that the GD library is enabled in your PHP configuration.
// Load the image
$image = imagecreatefromjpeg('image.jpg');
// Set the font file path
$font = 'arial.ttf';
// Set the text color
$textColor = imagecolorallocate($image, 255, 255, 255);
// Write text on 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);