PHP图像GD库无法显示图像

时间:2016-03-28 13:23:23

标签: php gd

我托盘生成uni代码并写入图像。这是我的代码:

    header('Content-type: image/png');

    /*root folder */
    if(!defined('TEJA_FOLDER')) define('TEJA_FOLDER', dirname(dirname(__DIR__)) . '/' , true);
    // Create Image From Existing File
    $jpg_image = imagecreatefrompng( TEJA_FOLDER.'images/white.png');
    // Allocate A Color For The Text
    $white = imagecolorallocate($jpg_image, 36, 143, 36);
    // Set Path to Font File
    $font           = TEJA_FOLDER.'fonts/Xerox Sans Serif Wide Bold.TTF'; //-------> font path
    // Set Text to Be Printed On Image
    $text = "This is a sunset!";
    // Print Text On Image
    imagettftext($jpg_image, 25, 45, 0, 0, $white, $font, database(TEJA_FOLDER));
    // Send Image to Browser
    imagepng($jpg_image);
    // Clear Memory
    imagedestroy($jpg_image);

function database($TEJA_FOLDER){

    /*require database connection */
    require_once( $TEJA_FOLDER . "helper/databasehelper.php" );
    /* generate unik code*/
    $code = $conn->query("select random_num from ( SELECT FLOOR(RAND() * 9999) AS random_num FROM list_produk ) dt WHERE NOT EXISTS (SELECT * FROM list_produk where random_num = kode_barang) AND NOT EXISTS (SELECT * FROM fb_group_tas where random_num = p_kode_id) LIMIT 1 ");
    $code   = mysqli_fetch_all($code,MYSQLI_ASSOC);
    $code   = $code[0]["random_num"];
    return $code;
}

我得到这样的错误" 图片http://localhost/myscript.php无法显示"

但如果我删除了数据库功能,我就没有错误,图像可以在浏览器中显示。

我缺少什么?

0 个答案:

没有答案