Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.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图像GD库无法显示图像_Php_Gd - Fatal编程技术网

PHP图像GD库无法显示图像

PHP图像GD库无法显示图像,php,gd,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 = imagecreatef

我使用托盘生成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;
}
我遇到这样的错误“图像无法显示”

但若我删除数据库功能,我并没有错误,图像可以显示在浏览器中


我遗漏了什么?

检查函数是否返回您期望的结果。为什么您在
$
两个
$TEJA_文件夹中都添加了
$
符号?您如何调用
database()
函数?“我没有错误”-因为您没有使用任何错误检查。请查阅以下链接,并将其应用到您的代码中。是否确定
数据库
功能不会引发任何损坏图像的警告/注意错误?注释
标题
函数,并检查是否正确。总之,我的函数数据库工作正常,此函数返回unik代码。