Imagettftext无法使用wordwrap / explode

时间:2013-10-29 05:49:34

标签: php imagettftext

嗨我这里有一个以前有效的代码。它获取文本输入并使用imagettftext在jpg上打印输入。我使用自动换行和爆炸来指定文本应该出现的位置。我看到其他帖子几乎与此相似,但我不想用于循环和计数器或事情本身。你觉得我的代码怎么办?它以前工作正常,但现在它不工作。提前感谢您的帮助。这是我的代码。请随时编辑它。

$story = "My story begins with " . $_POST['story'];

$newtext = wordwrap($story, 35, "\n", true);
$newertext = explode("\n", $newtext);
imagettftext($im, 8, 0, 280, 386, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 398, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 410, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 422, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 434, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 446, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 458, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 470, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 482, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 494, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 506, $black, $font2, $newertext);

1 个答案:

答案 0 :(得分:0)

explode返回一个数组,请检查如何在PHP中访问数组。

$story = "My story begins with " . $_POST['story'];

$newtext = wordwrap($story, 35, "\n", true);
$newertext = explode("\n", $newtext);
imagettftext($im, 8, 0, 280, 386, $black, $font2, $newertext[0]);
imagettftext($im, 8, 0, 280, 398, $black, $font2, $newertext[1]);
imagettftext($im, 8, 0, 280, 410, $black, $font2, $newertext[2]);