<?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);
imagedestroy($im);
?>