O
function text_center ($im, $str, font, $textColor, $pad_left, $padTop, $width_text, $font_size )
{
$arr = explode(' ', $str); $ret = "";
foreach($arr as $word){
$tmp_string = $ret.' '.$word;
$testbox = imagettfbbox($font_size, 0, $font, $tmp_string);
if($testbox[2] > $width_text) $ret.=($ret==""?"":"\n").$word;
else $ret.=($ret==""?"":" ").$word;
}
$arr = explode("\n", $ret);
foreach($arr as $str){
$testbox = imagettfbbox($font_size, 0, $font, $str);// Размер строки
$left_x = round(($width_text - ($testbox[2] - $testbox[0]))/2);
imagettftext($im, $font_size, 0, $left_x +$pad_left, ($padTop), $textColor, $font, $str);
$padTop=$padTop+ $font_size*1.5;
}
}