我一直在研究动态图像脚本。我搜索它的主要原因是我想显示数据库中的用户信息。这是我的问题:
<?php
header("Content-type:image/png");
$array=array("I am a monument to all your sins", "Currently making pizza","Best before 12/7/09", "Farming Onions");
function imagettftext_cr(&$im, $size, $angle, $x, $y, $color, $fontfile, $text)
{
// retrieve boundingbox
$bbox = imagettfbbox($size, $angle, $fontfile, $text);
// calculate deviation
$dx = ($bbox[2]-$bbox[0])/2.0 - ($bbox[2]-$bbox[4])/2.0; // deviation left-right
$dy = ($bbox[3]-$bbox[1])/2.0 + ($bbox[7]-$bbox[1])/2.0; // deviation top-bottom
// new pivotpoint
$px = $x-$dx;
$py = $y-$dy;
return imagettftext($im, $size, $angle, $px, $y, $color, $fontfile, $text);
}
$image = imagecreate(500,90);
$black = imagecolorallocate($image,0,0,0);
$grey_shade = imagecolorallocate($image,40,40,40);
$white = imagecolorallocate($image,255,255,255);
$text = $array[rand(0,sizeof($array)-1)];
$otherFont = 'open.ttf';
$font = 'open.ttf';
$name = "erlis";
$name = substr($name, 0, 25);
//BG text for Name
while($i<10){
imagettftext_cr($image,rand(2,40),rand(0,50),rand(10,500),rand(0,200),$grey_shade,$font,$name);
$i++;
}
//BG text for saying
while($i<10){
imagettftext_cr($image,rand(0,40),rand(90,180),rand(100,500),rand(200,500),$grey_shade,$otherFont,$text);
$i++;
}
// Main Text
imagettftext_cr($image,35,0,250,46,$white,$font,$name);
imagettftext_cr($image,10,0,250,76,$white,$otherFont,$text);
imagepng($image);
?>
这部分与简单的文本完美配合,没有 mysql 查询。但是当我尝试启动 mysql 查询时..假设$query = mysql_query("SELECT * FROM serverplayers WHERE id=1");
它只是破坏了图像。我使用什么样的表单并不重要,但它只会破坏我的图像。我怎样才能实现一些“从数据库中获取”代码?也许$_GET['']
或类似的东西。
我需要将$name="erlis";
其更改为用户信息。