Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将文本转换为图像时回显图像_Php_Image_Text - Fatal编程技术网

Php 将文本转换为图像时回显图像

Php 将文本转换为图像时回显图像,php,image,text,Php,Image,Text,我找到了将文本转换为图像的代码,我想回显结果 <?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($i

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

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

例如,我将代码保存到image.php,我可以通过

echo"<img src='image.php'>";
echo”“;
但我不想这样做,因为如果我这样做了,我就不能分配变量文本

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

在image.php中

替换

 $text = 'Testing...';

还有你要打印的代码

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


“我不能指定变量文本”是什么意思?您可以在URL中始终使用$\u GET-Parameters。我有很长的文本要传递。像一个600字的文章类型。可以这样传递吗?为什么要将文章转换为网站的图像?可以传递long-GET变量。虽然你可以考虑把所有的文本存储在一个数据库中,然后调用Simult.php id=1(其中ID然后通过MySQL点击查找表来获取文本)。对于使用特殊字体的头。@ IVORYSANTOS,如果这个解决方案帮助你,请把这个解决方案标记为接受的,这样人们就会知道你的问题已经解决了。
echo"<img src='image.php?text=AnotherText...'>";
<form action="image.php" method="post">
<textarea name="text"></textarea>
<input type="Submit" value="Submit">
</form>
$text=$_GET["text"];
$text=$_POST["text"];