Based on the previous example, here's how to center a string both horizontally and vertically...
<?php
function imagestringcentered ($img,$font,$text,$color) {
while (strlen($text) * imagefontwidth($font) > imagesx($img)) {
if ($font > 1) { $font--; }
else { break; }
}
$cy = (imagesy($img)/2) - (imagefontwidth($font)/2);
imagestring($img,$font,imagesx($img) / 2 - strlen($text) * imagefontwidth($font) / 2,$cy,$text,$color);
}
?>