使用PHP GD库绘制图像,不显示的问题
2012-12-28 14:59
483 查看
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"已成功安装";
}
<?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"已成功安装";
}
相关文章推荐
- 使用PHP GD库绘制图像,不显示的问题
- [PHP]GD库生成图像无法在浏览器正常显示的问题(更新:使用GD图像生成类发现错误必须及时清理缓存!)
- php使用GD图像库绘制输出图像出现乱码问题和图片上输出中文出现乱码问题解决方法。
- PHP 使用GD库生成验证码 在图像上绘制汉字
- PHP中使用GD库绘制折线图 折线统计图的绘制方法
- 一个 Qt 显示图片的控件(继承QWidget,使用QPixmap记录图像,最后在paintEvent进行绘制,可缩放)
- 使用matplotlib时pyplot.show()不显示图像的问题
- 处理2D图像和纹理——使用SpriteBatch类显示2D图像:加载和绘制图像
- PHP中使用GD库绘制折线图 折线统计图的绘制方法
- 关于PHP使用GD库生成的验证码无法在别处显示
- PHP使用header()向浏览器发送图像的乱码问题
- mac php 图片验证码无法显示问题,gd库没有freetype的问题
- PHP使用GD库生成图像验证码
- android 使用NDK进行图像处理(openCV)时的图像转换问题(灰度图显示)
- 关于使用phpqrcode二维码无法显示的问题
- matplotlib使用show方法后不能显示图像的问题
- 解决pandas无法在pycharm中使用plot()方法显示图像的问题
- 解决使用CImage类的Draw函数在显示图片时引起的图像失真问题
- 使用PHP的gd库出现问题
- PHP扩展之图像处理1——GD库使用及相关函数