使用PHP GD库绘制图像,不显示的问题

    xiaoxiao2021-03-25  79

    1.使用PHP中的GD库绘制图像,之后浏览器无法显示,GD库安装,配置也没什么错误,提示图像因本身有错无法显示,于是就在header() 前面使用ob_clean();然后使用浏览器就能正常的浏览了

    <?php 

      $height = 300;   $width = 300;   $im = imagecreatetruecolor($width, $height);   $white = imagecolorallocate ($im, 255, 255, 255);   $blue = imagecolorallocate ($im, 0, 0, 64);   imagefill($im, 0, 0, $blue);   imagestring($im, 10, 100, 120, 'Hello,PHP', $white);    ob_clean();   header ('Content-type: image/png');   imagepng($im);   imagedestroy($im);

    ?>

     

    ob_get_contents() - 返回输出缓冲区的内容ob_flush() - 冲刷出(送出)输出缓冲区中的内容ob_clean() - 清空(擦掉)输出缓冲区ob_end_flush() - 冲刷出(送出)输出缓冲区内容并关闭缓冲ob_end_clean() - 清空(擦除)缓冲区并关闭输出缓冲flush() - 刷新输出缓冲  

    2.判断GD库是否安装

    使用函数fnction_exists()

    if(function_exists('imagecreate')){    echo"已成功安装";    }

    转载请注明原文地址: https://ju.6miu.com/read-15986.html

    最新回复(0)