文档详情

图像函数验证码.doc

发布:2017-03-25约5.01千字共7页下载文档
文本预览下载声明
图像函数 imagecreatetruecolor 新建一个真彩色图像 imagecreatetruecolor ( int x_size, int y_size ) // x就是宽 ,y就是高 imagecolorallocate 为一幅图像分配颜色(调色板) imagecolorallocate ( resource image, int red, int green, int blue ) imagestring 绘图函数 imagestring ( resource image, font, int x, int y, 内容 , 颜色 ) imageline 画线函数 imageline ( resource image, int x1, int y1, int x2, int y2, int color ) imagesetpixel 画点函数 imagesetpixel ( resource image, int x, int y, int color ) imagettftext函数调用字体写入文字 imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text ) iconv(gb2312,UTF-8,新年快乐!); //首先要将文字转换成UTF8格式 eg: ?php header(Content-type:text/html;charset=gbk); session_start(); $str = ; for($i=0;$i4;$i++){ $str.=dechex(rand(1,15)); } $_SESSION[check_pic]=$str; $im = imagecreatetruecolor(50, 20); // 建立一幅 100X30 的图像 $bg = imagecolorallocate($im, 255, 0, 0 ); // 设置背景颜色 $textcolor = imagecolorallocate($im, rand(124,255), rand(0,124), rand(80,255)); //设置字体颜色 imagestring($im, 6,5,2, $str, $textcolor); // 把字符串写在图像左上角 header(Content-type: image/jpeg);// 输出图像 imagejpeg($im); ? 验证码: 效果: Html代码: !DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN /TR/html4/loose.dtd html head meta http-equiv=Content-Type content=text/html; charset=UTF-8 title验证码/title /head body h2验证码/h2 hr img border=0 name=imageField src=../test1.php?+Math.random()+ onclick=this.src=this.src+Math.random(); i点击图片刷新/i hr / img border=0 name=imageField src=../test2.php?+Math.random()+ onclick=this.src=this.src+Math.random(); i点击图片刷新/i hr / img border=0 name=imageField src=../test3.php?+Math.random()+ onclick=this.src=this.src+Math.random(); i点击图片刷新/i hr / /body /html Php 代码: Test1.php 对应第一种验证码: ?php //生成验证码图片 session_start(); Header(Content-type: image/PNG); srand((double)microtime()*1000000); $roundNum=rand(1000,9999); //把随机数存入session以便以后用 $_SESSION[sessionRound]=$roundNum; $im = imagecreate(58,28); $red = ImageColorAllocate($im, 255,
显示全部
相似文档