如何在宽图像文本中应用自动换行?

时间:2013-05-03 14:40:16

标签: php word-wrap

如何使用php wideimage将长文本写入小图像?

这是我使用的PHP代码,

$bg = WideImage::load("fbpostbg.png");
$final= $bg ->resize(400, 400);
$canvas = $final ->getCanvas();
$canvas->useFont('verdana.ttf', 14, $final->allocateColor(000, 000, 000));
$canvas->writeText('left +10', 'top +10', 'This is the text that I need to write to the above image, which is quite long...');

$final->output('jpg', 90);  

这会在图像画布外面输出一些文字并且无法看到...
我需要在我们写入图像的文本中进行自动换行,并且需要在其中获取带有全文的图像。

我是WideImage的新手,请帮帮我。

1 个答案:

答案 0 :(得分:1)

使用php的wordwrap函数,请参阅:http://php.net/manual/en/function.wordwrap.php

 $wrappedtext = wordwrap('This is the text that I need to write to the above image, which is quite long...', 60, "\n");
 $canvas->writeText('left +10', 'top +10',$wrappedtext);