应用PHP GD库中图像处理函数制作验证码
来源:互联网 发布:淘宝药品必须货到付款 编辑:程序博客网 时间:2024/05/21 16:21
<?php //开启session,之后会把验证码存入session,然后在后端与用户输入的验证码对比session_start();//新建一个真彩色图像$image=imagecreatetruecolor(100, 30);//定义白色$bgcolor=imagecolorallocate($image, 255, 255, 255);//填充颜色imagefill($image,0,0,$bgcolor);//验证码字符串$verify_str='';//循环产生四位字符for ($i=0; $i < 4; $i++) { //设置字体$font='img/msyh.ttc';$fontsize=16;//随机颜色$fontcolor=imagecolorallocate($image, mt_rand(0,120), mt_rand(0,120), mt_rand(0,120));$contentstr='23456789acefghijkmpqrstvwxyz';//截取字符$fontcontent=substr($contentstr,mt_rand(0,strlen($contentstr)-1),1);$verify_str.=$fontcontent;//随机位置$x=($i*100/4)+mt_rand(5,10);$y=mt_rand(20,25);//将文字写进图中imagettftext($image, $fontsize, mt_rand(-30,30), $x, $y, $fontcolor, $font, $fontcontent);}//中文验证码/*for ($i=0; $i < 4; $i++) {$font='img/msyh.ttc'; $fontsize=10;$fontcolor=imagecolorallocate($image, mt_rand(0,120), mt_rand(0,120), mt_rand(0,120));$contentstr='这是一段话';$fontcontent=mb_substr($contentstr,mt_rand(0,strlen($contentstr)/3-1),1,"utf-8");$verify_str.=$fontcontent;$x=($i*100/4)+mt_rand(5,10);$y=mt_rand(20,25);imagettftext($image, $fontsize, mt_rand(-30,30), $x, $y, $fontcolor, $font, $fontcontent);}*///把字符串存入session$_SESSION['verify']=$verify_str;//制作干扰项 200个点 三条线for ($i=0; $i <200 ; $i++) { $pointcolor=imagecolorallocate($image,mt_rand(50,200),mt_rand(50,200),mt_rand(50,200));imagesetpixel($image, mt_rand(1,99), mt_rand(1,29), $pointcolor);}for ($i=0; $i < 3; $i++) { $linecolor=imagecolorallocate($image, mt_rand(80,220), mt_rand(80,220), mt_rand(80,220));imageline($image, mt_rand(1,99), mt_rand(1,29), mt_rand(1,99), mt_rand(1,29), $linecolor);}//设置头信息,告诉浏览器输出的内容是图像header('Content-type:image/png');//输出图片imagepng($image);//销毁图像 释放与 image 关联的内存。imagedestroy($image); ?>
效果展示:
阅读全文
0 0
- 应用PHP GD库中图像处理函数制作验证码
- 运用php GD库的图像函数制作登录验证码图片
- PHP GD库相关图像生成和处理函数
- PHP基于GD库验证码的制作
- PHP使用GD库生成图像验证码
- PHP生成图像验证码(GD库的使用)
- [PHP] GD库(一):图像处理
- php使用GD库制作验证码,点击验证码或看不清会刷新验证码
- GD库 验证码函数
- [PHP] GD库(九)合并图像 imagecopymerge 函数(水印制作实例)
- 使用GD库制作验证码
- GD库图像处理
- PHP的gd库(图像生成和处理)的应用
- 利用GD图形库创建capchat图像(验证码的制作)
- GD 和图像处理 函数
- GD 和图像处理 函数
- GD 和图像处理 函数
- GD 和图像处理 函数
- P1578 奶牛浴场(极大化思想)
- CSS 北京属性 尺寸属性 盒子模型 定位 选择器
- Python 模块
- 对基础背包的公式理解
- ==和equals的区别
- 应用PHP GD库中图像处理函数制作验证码
- poj 3061 Subsequence 尺取
- Codeforces Gym 101174 H. Pascal's Hyper-Pyramids (记忆化搜索)
- uva11538(组合数学)象棋中的皇后
- Dubbo入门实例
- poj-4148-生理周期-C语言-枚举
- 2017暑假七林集训day25
- ubantu一开机就显示连接已断开
- NYOJ 题目636