<?php
// 创建 300x150 图像
$im = imagecreatetruecolor(300, 150);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// 将背景设置为白色
imagefilledrectangle($im, 0, 0, 299, 299, $white);
// 字体文件的路径
$font = './arial.ttf';
// 首先创建边界框
$bbox = imageftbbox(10, 0, $font, 'The PHP Documentation Group');
// 这是 X 和 Y 坐标
$x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2) - 5;
$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) - 5;
imagefttext($im, 10, 0, $x, $y, $black, $font, 'The PHP Documentation Group');
// 输出到浏览器
header('Content-Type: image/png');
imagepng($im);
?>