-1

我有一段代码可以将字符串转换为文本的图像。为了让它在我的实现中正常工作,它需要在一个单独的文件中。

所以我有这个:(generateimage.php)

<?php
$text = "this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test this'is'a'test";

$arrText = explode("\n", wordwrap($text, 69, "\n")); //change number 75 here to check the wordwrap

$im = @imagecreate(650, 500); //creates an image (width,height)
$background_color = imagecolorallocate($im, 0, 0, 0); //sets image background color
$y = 5; //vertical position of text

foreach ($arrText as $key => $arr)
{
$white = imagecolorallocate($im, 255, 255, 255); //sets text color
//imagestring($im, 5, 15, $y, trim($arr), $white); //create the text string for image,added trim() to remove unwanted chars
putenv('GDFONTPATH=' . realpath('.'));
imagettftext($im, 16, 0, 15, 16 + $y, $white, 'font.ttf', trim($arr));
$y = $y + 16 + 4; // size of font + newline space
}

imagepng($im);
imagedestroy($im);
?>

然后我在我的主页中调用它:

<img src="generateimage.php">

我想要做的是传递一个变量来填充generateimage.php 中的$text。我该怎么做呢?会有一篇文章要传递(超过 1000 字),我不认为通过 GET(URL)传递它会很好。

任何帮助将不胜感激。

4

1 回答 1

1

恕我直言,最简单的方法是将您的字符串放入数据库或文件中,或者通过某个脚本将会话变量放入,为选定的文本实例设置一些短 ID,然后使用 GET 将此 ID 传递给 generateimage.php

于 2013-03-20T10:40:40.930 回答