在PHP动态图像中使用从数据库中选择数据

在PHP动态图像中使用从数据库中选择数据,php,image,dynamic,Php,Image,Dynamic,我一直在研究动态图像脚本。我搜索它的主要原因是我想显示数据库中的用户信息。我的问题是: <?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(&a

我一直在研究动态图像脚本。我搜索它的主要原因是我想显示数据库中的用户信息。我的问题是:

<?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查询时,比如说,
$query=mysql\u query(“SELECT*FROM serverplayers,其中id=1”)它只是破坏了图像。无论我使用哪种形式,它只是阻止了我的图像。我如何实现一些“从数据库获取”代码?可能是
$\u GET['']
或类似的东西


我需要
$name=“erlis”更改为用户信息。

这似乎是如何调试beast的问题

  • 为自己构建一个打开图像的URL,并在任何浏览器中对其进行测试。差不多

    http://yourserver/images?id=1(请根据您的需要进行调整-这只是一个示例)

  • 将mysql序列添加到代码中

  • 取消对mimetype标题修改的注释,如下所示:

    //标题(“内容类型:图像/png”)

  • 在浏览器->php/mysql调试中运行步骤1中的链接,可能会提示您错误

  • 如果在浏览器上看不到任何内容,请尝试从浏览器菜单中的“查看源代码”