献上一款漂亮的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);
?>

效果如下:

最新文章

  1. CSS3 实现3D旋转木马效果
  2. Sass的学习
  3. easyUI数据表格datagrid之笔记2
  4. osgearth_city例子总结
  5. JDBC学习笔记(一)
  6. centos nginx,php添加到Service
  7. C# login with cookie and fiddler2
  8. iOS开发——新特性OC篇&amp;Objective新特性
  9. 大数据技术人年度盛事! BDTC 2016将于12月8-10日在京举行
  10. 开放Nginx在文件夹列表功能
  11. macvim打造python IDE
  12. BOS物流管理系统-第八天
  13. 3.Java集合总结系列:Set接口及其实现
  14. [2015-10-11]tfs2015 vs2013 配置持续集成
  15. 基于CSS UI开源框架汇总
  16. DNS查询相关
  17. JVM中的堆和栈
  18. 【C++】实现一个简单的单例模式
  19. solr学习之域的管理与中文分析器配置
  20. POJ 2896 另解暴力

热门文章

  1. (转)Android开发--常用的传感器总结
  2. 时间js
  3. Volley的post使用
  4. c#实现QQ群成员列表导出及邮件群发开篇
  5. POJ_3740 Easy Finding ——精确覆盖问题,DLX模版
  6. 关于服务端控件textbox的disabled属性设置为disabled后在服务端无法取值的问题
  7. 缓存 memcached 与 redis
  8. JSON数据的解析方法
  9. mysql跟踪执行的sql语句
  10. python---Redis 学习笔记