将中断放入写在图像上的文本中

问题描述:

If i write a text on a picture with code below, code tries to type all the text in one line. So text overflows out of the image like in picture1. I want to write it like in picture2.

If there is a function in php which enables writting like in picture2 what is it?
If there is no function to do that, how can i do it by writting my code? Can you give me a clue?

$text = $_POST['text']; // Text comes from a form.

$im = @imagecreate(700, 350)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagettftext($im, 22, 0, 5, 25,  $text_color, 'fonts/COOLVETICA RG.TTF', properText($text));
imagepng($im, 'image.png');

Picture1:

Picture one


Picture2:

enter image description here

如果我在下面带代码的图片上写文字,代码会尝试在一行中输入所有文字。 所以文字溢出图像,如图1所示。 我想在picture2中编写它。 p>

如果在php中有一个函数可以像在picture2中那样写入它是什么?
如果没有这样做的功能, 我怎么能写我的代码呢? 你能给我一个线索吗? p>

  $ text = $ _POST ['text'];  //文本来自一个表单。
 
 $ im = @imagecreate(700,350)
或者死(“无法初始化新的GD图像流”); 
 $ background_color = imagecolorallocate($ im,0,0  ,0); 
 $ text_color = imagecolorallocate($ im,233,14,91); 
imagettftext($ im,22,0,5,25,$ text_color,'fonts / COOLVETICA RG.TTF',properText($  text)); 
imagepng($ im,'image.png'); 
  code>  pre> 
 
 

Picture1: p> blockquote >

p>


\ n

图片2: p> blockquote>

p> div>

Put it in a bounding box using imagettfbbox() then the text will wrap. There's a full example on php.net:

http://www.php.net/manual/en/function.imagettfbbox.php