献上一款漂亮的手写PHP验证码
2024-10-19 14:54:02
献上一款漂亮的PHP验证码,可以根据个人需求作调整,代码如下(审美观不同,欢迎吐槽):
<?php
/**
* Author: xiongwei
* Email: 695704253@qq.com
*
* 注:本代码需要要用到 msyh.ttf 字体,请自行下载
**/ header("Content-type:image/png"); //图像尺寸
$width=180;
$height=70;
//字体样式
$font_style='./fontface/msyh.ttf';
//字体大小
$font_size=28;
//干扰点数量
$noise_num=40;
//干扰线数量
$line_num=10; $expression='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$expression=substr(str_shuffle($expression),0,4); $img=imagecreatetruecolor($width,$height);
$bdcolor=imagecolorallocate($img,170,170,170);
$bgcolor=imagecolorallocate($img,250,250,250); imagefilledrectangle($img,0,0,$width,$height,$bgcolor);
imagerectangle($img,0,0,$width-1,$height-1,$bdcolor); $x=10;
$y=ceil(($height+$font_size)/2);
for($i=0;$i<strlen($expression);$i++){
imagettftext($img,$font_size,mt_rand(-30,30),$x,$y,imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)),$font_style,$expression[$i]);
$x+=30;
}
for($i=0;$i<$noise_num;$i++){
imagesetpixel($img,mt_rand(1,$width-1),mt_rand(1,$height-1),imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)));
}
for($i=0;$i<$line_num;$i++){
imagearc($img,mt_rand(-10,0),mt_rand(-10,0),mt_rand(20,400),mt_rand(20,400),50,44,imagecolorallocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255)));
//imagearc()
}
imagepng($img);
imagedestroy($img);
?>
效果如下:
最新文章
- CSS3 实现3D旋转木马效果
- Sass的学习
- easyUI数据表格datagrid之笔记2
- osgearth_city例子总结
- JDBC学习笔记(一)
- centos nginx,php添加到Service
- C# login with cookie and fiddler2
- iOS开发——新特性OC篇&;Objective新特性
- 大数据技术人年度盛事! BDTC 2016将于12月8-10日在京举行
- 开放Nginx在文件夹列表功能
- macvim打造python IDE
- BOS物流管理系统-第八天
- 3.Java集合总结系列:Set接口及其实现
- [2015-10-11]tfs2015 vs2013 配置持续集成
- 基于CSS UI开源框架汇总
- DNS查询相关
- JVM中的堆和栈
- 【C++】实现一个简单的单例模式
- solr学习之域的管理与中文分析器配置
- POJ 2896 另解暴力