/*
*说明:函数功能是生成验证码
* 参数说明:输入 长度,宽度,高度
*/
function vcode($_code_length = , $_width = , $_height = ){ $_font=dirname(__FILE__).'/font/Elephant.ttf';//注意字体路径要写对,否则显示不了图片 $_fontsize=$_height/1.8;
$_nmsg="";
for($i=;$i<$_code_length;$i++){
$_nmsg .= dechex(mt_rand(,));
}
if(!isset($_SESSION)){
session_start();
} $_SESSION["vcode"] = $_nmsg; $_img = imagecreatetruecolor($_width, $_height); $_white = imagecolorallocate($_img, , , ); imagefill($_img, , , $_white); $_gray = imagecolorallocate($_img, , , ); imagerectangle($_img, , , $_width-, $_height-, $_gray); for ($i=; $i < ; $i++) {
$_md_color = imagecolorallocate($_img, mt_rand(,), mt_rand(,), mt_rand(,));
imageline($_img, mt_rand(,$_width), mt_rand(, $_height),mt_rand(,$_width), mt_rand(, $_height), $_md_color);
} for ($i=; $i < ; $i++) {
$_md_color = imagecolorallocate($_img, mt_rand(,), mt_rand(,), mt_rand(,));
imagestring($_img, , mt_rand(,$_width-), mt_rand(, $_height-), "*", $_md_color);
} for ($i=; $i < $_code_length ; $i++) {
$_md_color = imagecolorallocate($_img, mt_rand(,), mt_rand(,), mt_rand(,));
//imagestring($_img, 5, $i * $_width/$_code_length+ mt_rand(1, 10), mt_rand(1, $_height/2), $_SESSION["vcode"][$i], $_md_color);
imagettftext($_img,$_fontsize,mt_rand(-,),$_fontsize*$i+mt_rand(,),$_height / 1.4,$_md_color,$_font,$_SESSION["vcode"][$i]);
} header("Content-Type:image/png"); imagepng($_img); imagedestroy($_img);
}

需要一个字体文件 可以百度下载一个

最新文章

  1. php多文件上传
  2. Windows 下 pdf2word 的可用软件记录
  3. 关于win10输入法问题(打不出中文)解决方法
  4. &lt;meta http-equiv=&quot;refresh&quot; content=&quot;0; url=&quot;&gt;是什么意思?
  5. fcitx 无法启动
  6. 删除SSMS中保存的帐户信息
  7. 学容器必须懂 bridge 网络 - 每天5分钟玩转 Docker 容器技术(32)
  8. hdu 5909 Tree Cutting [树形DP fwt]
  9. BZOJ_1316_树上的询问_点分治
  10. 从url中获得域名
  11. python之数据类型补充、集合、深浅copy
  12. Java(6)for循环
  13. BeanUtils的copyproPerties方法的用法
  14. java导出csv文件使用Excel打开乱码问题
  15. linux系统添加swap(虚拟内存)分区
  16. 基于OSGI.NET的MVC插件式开发
  17. B. Salty Fish Go! -期望题(瞎搞题)
  18. Python爬虫实战四之抓取淘宝MM照片
  19. Spark history Server配置实用
  20. 如何测试Linux 中的wait函数能不能等待子进程的子进程?

热门文章

  1. Fn+F1-F12,避免使用FN+
  2. PHP实现HTML页面静态化
  3. PHP中继承
  4. Java容器深入浅出之String、StringBuffer、StringBuilder
  5. Windows搭建Log4Net+FileBeat+ELK日志分析系统过程
  6. Vue使用,异步获取日期时间后格式成&quot;/Date(1333245600000+0800)/&quot; 转换成正常格式
  7. BZOJ 2109 航空管制(拓扑排序+贪心)
  8. HN2018省队集训
  9. 使DIV相对窗口大小左右拖动始终水平居中
  10. C 位段,位域