À l'aide de la fonction imagettftext avec plusieurs lignes? Quiconque fait cela avant?

Je suis de la création de texte transparente -> images png avec php et c'est très bien. Le seul problème est que je veux avoir la possibilité d'avoir le texte de word wrap en raison d'une largeur fixe.. Ou, sinon, d'être en mesure d'insérer des lignes de rupture dans le texte. Quelqu'un avait une exp de faire ceci? voici mon code...

<?php

$font = 'arial.ttf';
$text = 'Cool Stuff! this is nice LALALALALA LALA HEEH EHEHE';
$fontSize = 20;

$bounds = imagettfbbox($fontSize, 0, $font, $text); 

$width = abs($bounds[4]-$bounds[6]); 
$height = abs($bounds[7]-$bounds[1]); 



$im = imagecreatetruecolor($width, $height);
imagealphablending($im, false);
imagesavealpha($im, true);


$trans = imagecolorallocatealpha($im, 255, 255, 255, 127);

//Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);


imagecolortransparent($im, $black);
imagefilledrectangle($im, 0, 0, $width, $height, $trans);


//Add the text
imagettftext($im, $fontSize, 0, 0, $fontSize-1, $grey, $font, $text);


imagepng($im, "image.png");
imagedestroy($im);


?>

OriginalL'auteur ionfish | 2011-05-29