分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

php 验证码 图像存在错误无法显示

发布时间:2023-09-06 01:17责任编辑:熊小新关键词:验证码
<?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);?>
<?php//无bug的国旗测试//ob_clean();header("Content-Type:image/jpeg");$ing = imagecreatetruecolor(700,410);//新建一个真彩色图像,返回值为一个图像标识符,背景默认为黑色,参数(x_size*y_size)$red = imagecolorallocate($ing,255,0,0);//定义背景颜色$yellow = imagecolorallocate($ing,237,231,32);//定义黄色imagefill($ing,0,0,$red);//填充颜色,以坐标(0,0)开始起填充//数组坐标,表示(x1,y1,x2,y2,x3,y3.....x11,y11);$a = array(90,30,108,73,157,73,119,102,135,152,93,123,52,152,66,102,29,74,76,73,90,30);imagefilledpolygon($ing,$a,10,$yellow);//画一个多边形:10表示顶点总数,$yellow表示填充色$a1 = array(229,25,229,43,248,48,229,55,229,74,217,60,198,66,210,50,197,34,218,39,229,25);imagefilledpolygon($ing,$a1,10,$yellow);$a2 = array(227,108,227,127,245,134,228,139,227,157,215,143,196,149,208,132,196,117,215,122,227,108);imagefilledpolygon($ing,$a2,10,$yellow);$a3 = array(163,184,163,204,181,211,163,216,163,234,152,220,132,225,144,209,132,193,151,199,163,184);imagefilledpolygon($ing,$a3,10,$yellow);$a4 = array(65,209,65,228,84,235,65,240,65,259,54,245,33,249,46,233,34,217,53,224,68,209);imagefilledpolygon($ing,$a4,10,$yellow);imagejpeg($ing);imagedestroy($ing);?>

 

注!关于验证码无法显示,首先判断GD库是否开启;

默认配置下,php输出是先到输出缓冲区(output_buffering),只要数据还没有真正发送到浏览器(严格来说是tcp buffer),那么还是有机会清空先前的缓冲区里面的数据,使用内置的ob_clean函数即可。

php 验证码 图像存在错误无法显示

原文地址:http://www.cnblogs.com/fan-bk/p/7660615.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved