Another way to wrap and center using wordwrap and learning the number of lines in the result of that wordwrap
<?php
$text="privet privet privet privet privet privet2 privet2 privet2 privet2 privet2 privet3";
$text=wordwrap($text, 35, "\n", TRUE);
header("Content-Type: image/png");
$im = @imagecreate(460, 215)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0x00, 0x00, 0x00);
$text_color = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$font = "verdana.ttf";
$font_size = 20;
$angle = 0;
$splittext = explode ( "\n" , $text );
$lines = count($splittext);
foreach ($splittext as $text) {
$text_box = imagettfbbox($font_size,$angle,$font,$text);
$text_width = abs(max($text_box[2], $text_box[4]));
$text_height = abs(max($text_box[5], $text_box[7]));
$x = (imagesx($im) - $text_width)/2;
$y = ((imagesy($im) + $text_height)/2)-($lines-2)*$text_height;
$lines=$lines-1;
imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font, $text);
}
imagepng($im);
imagedestroy($im);
?>