1 Star 0 Fork 57

凯纳颜值担当,唉 / ImageVerifyCode

forked from Reevy / ImageVerifyCode 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
code_char.php 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
Reevy 提交于 2015-05-04 10:53 . initialize commit
<?php
session_start();
getCode(4,60,20);
function getCode($num,$w,$h) {
// 去掉了 0 1 O l 等
$str = "23456789abcdefghijkmnpqrstuvwxyz";
$code = '';
for ($i = 0; $i < $num; $i++) {
$code .= $str[mt_rand(0, strlen($str)-1)];
}
//将生成的验证码写入session,备验证页面使用
$_SESSION["helloweba_char"] = $code;
//创建图片,定义颜色值
Header("Content-type: image/PNG");
$im = imagecreate($w, $h);
$black = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
$gray = imagecolorallocate($im, 118, 151, 199);
$bgcolor = imagecolorallocate($im, 235, 236, 237);
//画背景
imagefilledrectangle($im, 0, 0, $w, $h, $bgcolor);
//画边框
imagerectangle($im, 0, 0, $w-1, $h-1, $gray);
//imagefill($im, 0, 0, $bgcolor);
//在画布上随机生成大量点,起干扰作用;
for ($i = 0; $i < 80; $i++) {
imagesetpixel($im, rand(0, $w), rand(0, $h), $black);
}
//将字符随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
$strx = rand(3, 8);
for ($i = 0; $i < $num; $i++) {
$strpos = rand(1, 6);
imagestring($im, 5, $strx, $strpos, substr($code, $i, 1), $black);
$strx += rand(8, 14);
}
imagepng($im);
imagedestroy($im);
}
?>
PHP
1
https://gitee.com/lixiaoweb/ImageVerifyCode.git
git@gitee.com:lixiaoweb/ImageVerifyCode.git
lixiaoweb
ImageVerifyCode
ImageVerifyCode
master

搜索帮助