将数据传递到另一个页面,以便在GD映像生成函数中使用


Passing data to another page to be used in a GD image generation function

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

(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)传递会很好。

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