Imagettftext 不适用于自动换行/分解


Imagettftext not working with wordwrap/explode

嗨,我

这里有一个以前有效的代码。 它获取文本输入并使用 JPG 上的 imagettftext 打印输入。 我使用自动换行和爆炸来分配文本应该出现的位置。我看过其他几乎与此类似的帖子,但我不想用于循环和计数器或类似的东西。你认为我的代码做错了什么?它以前工作正常,但现在它不起作用。提前感谢您的任何帮助。这是我的代码。请随意编辑它。

$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);

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]);