将文本转换为图像的回显图像


echo image from converting text-to-image

我找到了将文本转换为图像的代码,我想回显结果

<?php
// Set the content-type
header('Content-type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?> 

例如,我将该代码保存到图像.php,我可以通过以下方式回显该图像

echo"<img src='image.php'>";

但我不想那样做,因为如果我这样做了,我就无法分配可变文本。

有没有其他方法可以从该代码打印图像?

在你的

图像中.php

取代

 $text = 'Testing...';

 $text=$_GET["text"];

和要打印的代码

echo"<img src='image.php?text=AnotherText...'>";

希望这是你想要的?

编辑:

<form action="image.php" method="post">
<textarea name="text"></textarea>
<input type="Submit" value="Submit">
</form>

在您的图像中.php文件,而不是

$text=$_GET["text"];

$text=$_POST["text"];