没有合适的资源?快使用搜索试试~ 我知道了~
php生成动态验证码gif图片
0 下载量 37 浏览量
2020-12-18
17:01:28
上传
评论
收藏 45KB PDF 举报
温馨提示
试读
3页
这是一个通过php生成的动态验证码图片的示例,重点是可以运行哦!下面先发下效果图: 下面是php生成动态验证码需要用到的相关类和函数。 <?php /** *ImageCode 生成包含验证码的GIF图片的函数 *@param $string 字符串 *@param $width 宽度 *@param $height 高度 **/ function ImageCode($string='',$width=75,$height=25){ $authstr=$string?$string:((time()%2==0)?mt_rand(1000,9999):mt_rand(10000,9
资源详情
资源评论
资源推荐
php生成动态验证码生成动态验证码gif图片图片
这是一个通过php生成的动态验证码图片的示例,重点是可以运行哦!下面先发下效果图:
下面是php生成动态验证码需要用到的相关类和函数。
<?php
/**
*ImageCode 生成包含验证码的GIF图片的函数
*@param $string 字符串
*@param $width 宽度
*@param $height 高度
**/
function ImageCode($string='',$width=75,$height=25){
$authstr=$string?$string:((time()%2==0)?mt_rand(1000,9999):mt_rand(10000,99999));
$board_width=$width;
$board_height=$height;
// 生成一个32帧的GIF动画
for($i=0;$i<32;$i++){
ob_start();
$image=imagecreate($board_width,$board_height);
imagecolorallocate($image,0,0,0);
// 设定文字颜色数组
$colorList[]=ImageColorAllocate($image,15,73,210);
$colorList[]=ImageColorAllocate($image,0,64,0);
$colorList[]=ImageColorAllocate($image,0,0,64);
$colorList[]=ImageColorAllocate($image,0,128,128);
$colorList[]=ImageColorAllocate($image,27,52,47);
$colorList[]=ImageColorAllocate($image,51,0,102);
$colorList[]=ImageColorAllocate($image,0,0,145);
$colorList[]=ImageColorAllocate($image,0,0,113);
$colorList[]=ImageColorAllocate($image,0,51,51);
$colorList[]=ImageColorAllocate($image,158,180,35);
$colorList[]=ImageColorAllocate($image,59,59,59);
$colorList[]=ImageColorAllocate($image,0,0,0);
$colorList[]=ImageColorAllocate($image,1,128,180);
$colorList[]=ImageColorAllocate($image,0,153,51);
$colorList[]=ImageColorAllocate($image,60,131,1);
$colorList[]=ImageColorAllocate($image,0,0,0);
$fontcolor=ImageColorAllocate($image,0,0,0);
$gray=ImageColorAllocate($image,245,245,245);
$color=imagecolorallocate($image,255,255,255);
$color2=imagecolorallocate($image,255,0,0);
imagefill($image,0,0,$gray);
$space=15;// 字符间距
if($i>0){// 屏蔽第一帧
$top=0;
for($k=0;$k<strlen($authstr);$k++){
$colorRandom=mt_rand(0,sizeof($colorList)-1);
$float_top=rand(0,4);
$float_left=rand(0,3);
imagestring($image,6,$space*$k,$top+$float_top,substr($authstr,$k,1),$colorList[$colorRandom]);
}
}
for($k=0;$k<20;$k++){
$colorRandom=mt_rand(0,sizeof($colorList)-1);
imagesetpixel($image,rand()%70,rand()%15,$colorList[$colorRandom]);
}
// 添加干扰线
for($k=0;$k<3;$k++){
$colorRandom=mt_rand(0,sizeof($colorList)-1);
$todrawline=1;
if($todrawline){
imageline($image,mt_rand(0,$board_width),mt_rand(0,$board_height),mt_rand(0,$board_width),mt_rand(0,$board_height),$colorList[$colorRandom]);
}else{
$w=mt_rand(0,$board_width);
$h=mt_rand(0,$board_width);
imagearc($image,$board_width-floor($w / 2),floor($h / 2),$w,$h, rand(90,180),rand(180,270),$colorList[$colorRandom]);
}
}
imagegif($image);
imagedestroy($image);
$imagedata[]=ob_get_contents();
ob_clean();
++$i;
}
$gif=new GIFEncoder($imagedata);
Header('Content-type:image/gif');
echo $gif->GetAnimation();
}
/**
*GIFEncoder类
**/
Class GIFEncoder{
var $GIF="GIF89a"; /* GIF header 6 bytes */
var $VER="GIFEncoder V2.06"; /* Encoder version */
weixin_38702931
- 粉丝: 10
- 资源: 907
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 超声波测距实验_单片机C语言实例(纯C语言源代码).zip
- MTSP的求解程序代码.zip
- rust 编译原理.pdf
- 基于STM32 NUCLEO板设计彩色LED照明灯(纯cubeMX开发).zip
- [新闻文章]多讯文章管理系统 v2.5_dxnews25.rar
- [信息办公]电信计费系统完整代码_netctossconformity.rar
- 用有参函数控制P0口8位LED流水速度_单片机C语言实例(纯C语言源代码).zip
- [其他类别]QQ邮箱编辑器 v1.0 (小小菜刀PHP版)_htmleditor_php.rar
- 综合分析:图像处理、机器视觉与深度学习的概念、关系及应用
- ASP外观专利图像检索平台(源代码+论文).rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0