没有合适的资源?快使用搜索试试~ 我知道了~
适用于自定义的验证码类! <?php /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ Class Image{ private $img; public $width = 85; public $height = 25; public $code; pub
资源推荐
资源详情
资源评论
PHP编写的图片验证码类文件分享编写的图片验证码类文件分享
适用于自定义的验证码类!
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
Class Image{
private $img;
public $width = 85;
public $height = 25;
public $code;
public $code_len = 4;
public $code_str = "329832983DSDSKDSLKQWEWQ2lkfDSFSDjfdsfdsjwlkfj93290KFDSKJFDSOIDSLK";
public $bg_color = '#DCDCDC';
public $font_size = 16;
public $font = 'font.ttf';
public $font_color = '#000000';
//创建验证码饿字符创
public function create_code(){
$code = '';
for( $i=0;$i<$this->code_len;$i++ ){
$code .= $this->code_str[mt_rand(0, strlen($this->code_str)-1)];
}
return $this->code = $code;
}
//输出图像
public function getImage(){
$w = $this->width;
$h = $this->height;
$bg_color = $this->bg_color;
$img = imagecreatetruecolor($w, $h);
$bg_color = imagecolorallocate($img,
hexdec(substr($bg_color, 1,2)), hexdec(substr($bg_color, 3,2)), hexdec(substr($bg_color, 5,2)));
imagefill($img, 0, 0, $bg_color);
$this->img = $img;
$this->create_font();
$this->create_pix();
$this->show_code();
}
//写入验证码
public function create_font(){
$this->create_code();
$color = $this->font_color;
$font_color = imagecolorallocate($this->img, hexdec(substr($color,1,2)), hexdec(substr($color, 3,2)),
hexdec(substr($color,5,2)));
$x = $this->width/$this->code_len;
for( $i=0;$i<$this->code_len;$i++ ){
$txt_color = imagecolorallocate($this->img, mt_rand(0,100), mt_rand(0, 150), mt_rand(0, 200));
imagettftext($this->img, $this->font_size, mt_rand(-30, 30), $x*$i+mt_rand(3, 6), mt_rand($this->height/1.2, $this->height),
$txt_color, $this->font , $this->code[$i]);
//imagestring($this->img, $this->font_size, $x*$i+mt_rand(3, 6),mt_rand(0, $this->height/4) , $this->code[$i], $font_color);
}
$this->font_color = $font_color;
}
//画干扰线
public function create_pix(){
$pix_color= $this->font_color;
for($i=0;$i<100;$i++){
资源评论
weixin_38742124
- 粉丝: 3
- 资源: 897
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 50R4 R5 K8 X4 ECHO 55K8 58R5 58X原理图.pdf
- “人力资源+大数据+薪酬报告+涨薪调薪”
- “人力资源+大数据+薪酬报告+涨薪调薪”
- 牙齿图像分割-基于2D全景图像的牙齿分割算法实现-附项目源码-优质项目分享.zip
- 亚马逊爬虫抓取商品信息并数据分析.zip
- 基于MATLAB的车牌识别系统
- 海信智能电视刷机数据 LED40K160JD(0002)BOM3 生产用软件数据 务必确认机编一致 强制刷机 整机USB升级程序
- 【STL源码剖析】deque 的使用
- 车辆综合管控平台.zip
- 海信智能电视刷机数据 LED40K160JD(0000)BOM1 生产用软件数据 务必确认机编一致 强制刷机 整机USB升级程序
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功