我在while循环中使用下面的代码,因此当页面到来时它会将文本显示为图像。
<?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
$con=mysqli_connect("localhost","root","","databasename");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT * FROM tbl_demo";
if ($result=mysqli_query($con,$sql))
{
while ($row=mysqli_fetch_row($result))
{ ?>
<tr>
<td align="center" ><?php echo $row[0]; ?></td>
<td align="center"><?php echo $row[1]; ?></td>
<td align="center"><img src="txt2img.php?txt=<?php echo $row[1]; ?>&font=<?php echo $row[2]; ?>" border="0"></td>
</tr>
<?php }
mysqli_free_result($result);
}
mysqli_close($con);
?>
注意: - 我想显示像dafont.com网站这样的字体。请帮助我尝试了很多时间,并且工作不正常。