开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from 后盾人/v2015
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
video
/
webApp
/
admin
/
hdphp
/
code
/
Code.php
video
/
webApp
/
admin
/
hdphp
/
code
/
Code.php
Code.php 5.01 KB
一键复制 编辑 原始数据 按行查看 历史
后盾人 提交于 2017年05月02日 15:00 +08:00 . no message
<?php
/** .-------------------------------------------------------------------
* | Software: [HDCMS framework]
* | Site: www.hdcms.com
* |-------------------------------------------------------------------
* | Author: 向军 <2300071698@qq.com>
* | WeChat: aihoudun
* | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
* '-------------------------------------------------------------------*/
namespace hdphp\code;
class Code {
//资源
private $img;
//画布宽度
private $width = 100;
//画布高度
private $height = 30;
//背景颜色
private $bgColor = '#ffffff';
//验证码
private $code;
//验证码的随机种子
private $codeStr = '23456789abcdefghjkmnpqrstuvwsyz';
//验证码长度
private $codeLen = 4;
//验证码字体
private $font;
//验证码字体大小
private $fontSize = 16;
//验证码字体颜色
private $fontColor = '';
public function __construct() {
}
//创建验证码
public function make() {
if ( empty( $this->font ) ) {
$this->font = __DIR__ . '/font.ttf';
}
$this->create();//生成验证码
header( "Content-type:image/png" );
imagepng( $this->img );
imagedestroy( $this->img );
exit;
}
//设置字体文件
public function font( $font ) {
$this->font = $font;
return $this;
}
//设置文字大小
public function fontSize( $fontSize ) {
$this->fontSize = $fontSize;
return $this;
}
//设置字体颜色
public function fontColor( $fontColor ) {
$this->fontColor = $fontColor;
return $this;
}
//验证码数量
public function num( $num ) {
$this->codeLen = $num;
return $this;
}
//设置宽度
public function width( $width ) {
$this->width = $width;
return $this;
}
//设置高度
public function height( $height ) {
$this->height = $height;
return $this;
}
//设置背景颜色
public function background( $color ) {
$this->bgColor = $color;
return $this;
}
//返回验证码
public function get() {
return $_SESSION['code'];
}
//生成验证码
private function createCode() {
$code = '';
for ( $i = 0;$i < $this->codeLen;$i ++ ) {
$code .= $this->codeStr [ mt_rand( 0, strlen( $this->codeStr ) - 1 ) ];
}
$this->code = strtoupper( $code );
$_SESSION['code'] = $this->code;
}
//建画布
private function create() {
if ( ! $this->checkGD() ) {
return FALSE;
}
$w = $this->width;
$h = $this->height;
$bgColor = $this->bgColor;
$img = imagecreatetruecolor( $w, $h );
$bgColor = imagecolorallocate( $img, hexdec( substr( $bgColor, 1, 2 ) ), hexdec( substr( $bgColor, 3, 2 ) ), hexdec( substr( $bgColor, 5, 2 ) ) );
imagefill( $img, 0, 0, $bgColor );
$this->img = $img;
$this->createLine();
$this->createFont();
$this->createPix();
$this->createRec();
}
//画线
private function createLine() {
$w = $this->width;
$h = $this->height;
$line_color = "#dcdcdc";
$color = imagecolorallocate( $this->img, hexdec( substr( $line_color, 1, 2 ) ), hexdec( substr( $line_color, 3, 2 ) ), hexdec( substr( $line_color, 5, 2 ) ) );
$l = $h / 5;
for ( $i = 1;$i < $l;$i ++ ) {
$step = $i * 5;
imageline( $this->img, 0, $step, $w, $step, $color );
}
$l = $w / 10;
for ( $i = 1;$i < $l;$i ++ ) {
$step = $i * 10;
imageline( $this->img, $step, 0, $step, $h, $color );
}
}
//画矩形边框
private function createRec() {
//imagerectangle($this->img, 0, 0, $this->width - 1, $this->height - 1, $this->fontColor);
}
//写入验证码文字
private function createFont() {
$this->createCode();
$color = $this->fontColor;
if ( ! empty( $color ) ) {
$fontColor = imagecolorallocate( $this->img, hexdec( substr( $color, 1, 2 ) ), hexdec( substr( $color, 3, 2 ) ), hexdec( substr( $color, 5, 2 ) ) );
}
$x = ( $this->width - 10 ) / $this->codeLen;
for ( $i = 0;$i < $this->codeLen;$i ++ ) {
if ( empty( $color ) ) {
$fontColor = imagecolorallocate( $this->img, mt_rand( 50, 155 ), mt_rand( 50, 155 ), mt_rand( 50, 155 ) );
}
imagettftext( $this->img, $this->fontSize, mt_rand( - 30, 30 ), $x * $i + mt_rand( 6, 10 ), mt_rand( $this->height / 1.3, $this->height - 5 ), $fontColor, $this->font, $this->code [ $i ] );
}
$this->fontColor = $fontColor;
}
//画线
private function createPix() {
$pix_color = $this->fontColor;
for ( $i = 0;$i < 50;$i ++ ) {
imagesetpixel( $this->img, mt_rand( 0, $this->width ), mt_rand( 0, $this->height ), $pix_color );
}
for ( $i = 0;$i < 2;$i ++ ) {
imageline( $this->img, mt_rand( 0, $this->width ), mt_rand( 0, $this->height ), mt_rand( 0, $this->width ), mt_rand( 0, $this->height ), $pix_color );
}
//画圆弧
for ( $i = 0;$i < 1;$i ++ ) {
// 设置画线宽度
imagearc( $this->img, mt_rand( 0, $this->width ), mt_rand( 0, $this->height ), mt_rand( 0, $this->width ), mt_rand( 0, $this->height ), mt_rand( 0, 160 ), mt_rand( 0, 200 ), $pix_color );
}
imagesetthickness( $this->img, 1 );
}
//验证GD库
private function checkGD() {
return extension_loaded( 'gd' ) && function_exists( "imagepng" );
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

后盾人视频教程代码,收到 Star 我们会更有动力。
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/itcode-itcode/video.git
git@gitee.com:itcode-itcode/video.git
itcode-itcode
video
video
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /