My version of the centered string, it decreases the font number (since I've noticed smaller numbers are smaller fonts) until 1 if the string won't fit. Then it will give up.
<?php
function imagestringcentered ($img,$font,$cy,$text,$color) {
while (strlen($text) * imagefontwidth($font) > imagesx($img)) {
if ($font > 1) { $font--; }
else { break; }
}
imagestring($img,$font,imagesx($img) / 2 - strlen($text) * imagefontwidth($font) / 2,$cy,$text,$color);
}
?>