您的位置:首页 > 编程语言 > PHP开发

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

2012-12-28 14:59 429 查看
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"已成功安装";

   }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: