//首先开启session

session_start();

//定义前台显示验证码长&宽

$image_width = 120;

$image_height = 40;

$characters_on_image = 6;

$font = './monofont.ttf';

//The characters that can be used in the CAPTCHA code.

//avoid confusing characters (l 1 and i for example)

$possible_letters = '23456789bcdfghjkmnpqrstvwxyz';

$random_dots = 10;

$random_lines = 30;

$captcha_text_color="0x142864";

$captcha_noice_color = "0x142864";

//定义要生成验证码的字符串

$code = '';

$i = 0;

while ($i < $characters_on_image) {

$code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);

$i++;

}

$font_size = $image_height * 0.75;

$image = @imagecreate($image_width, $image_height);

/* setting the background, text and noise colours here */

$background_color = imagecolorallocate($image, 255, 255, 255);

$arr_text_color = hexrgb($captcha_text_color);

$text_color = imagecolorallocate($image, $arr_text_color['red'],

$arr_text_color['green'], $arr_text_color['blue']);

$arr_noice_color = hexrgb($captcha_noice_color);

$image_noise_color = imagecolorallocate($image, $arr_noice_color['red'],

$arr_noice_color['green'], $arr_noice_color['blue']);

/* generating the dots randomly in background */

for( $i=0; $i

imagefilledellipse($image, mt_rand(0,$image_width),

mt_rand(0,$image_height), 2, 3, $image_noise_color);

}

/* generating lines randomly in background of image */

for( $i=0; $i

imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height),

mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color);

}

/* create a text box and add 6 letters code in it */

$textbox = imagettfbbox($font_size, 0, $font, $code);

$x = ($image_width - $textbox[4])/2;

$y = ($image_height - $textbox[5])/2;

imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code);

/* Show captcha image in the page html page */

header('Content-Type: image/jpeg');// defining the image type to be shown in browser widow

imagejpeg($image);//showing the image

imagedestroy($image);//destroying the image instance

//设置session,做验证

$_SESSION['6_letters_code'] = $code;

function hexrgb ($hexstr)

{

$int = hexdec($hexstr);

return array("red" => 0xFF & ($int >> 0x10),

"green" => 0xFF & ($int >> 0x8),

"blue" => 0xFF & $int);

}

php验证码图像程序,完美的php生成验证码程序代码-图像处理-Php教程相关推荐

  1. ONVIF协议网络摄像机(IPC)客户端程序开发使用gSOAP生成ONVIF框架代码(C++)03-->Windows

    其它的不多说,直接开始步骤. 我的版本是2.8.109,目前最新版本. 实际上,onvif的源码是兼容Linux.Windows版本的,例如如果你已经在这篇文章ONVIF协议网络摄像机(IPC)客户端 ...

  2. html前端登录验证码,前端登录页面开发_js生成验证码并验证

    /p> 前端集成开发工具: margin: 0; padding: 0; } a { text-decoration: none; } .main_bar { width: 100%; heig ...

  3. PHP生产一个验证码图片,PHP使用GD库生成验证码图片,实现图片验证

    本文记录从php 下载配置GD图片生成库 到使用该库生成验证码图片,网页上实现验证码. 使用技术: php使用GD库绘图 [php版本7.3] php session 缓存 实现最终效果: 一. 配置 ...

  4. Qt发布安装程序(打包依赖库+生成安装程序)

    目录 打包Qt依赖库 打包其它依赖库 生成安装程序 下载并安装Inno Setup 5 使用Inno Setup 5 Qt编译好的项目是不能直接被双击运行的,如下所示. 缺少了依赖的库,需要添加进去. ...

  5. java web 生成验证码_Javaweb开发中通过Servlet生成验证码图片

    一.BufferedImage类介绍 生成验证码图片主要用到了一个BufferedImage类,如下: 创建一个DrawImage Servlet,用来生成验证码图片 package gacl.res ...

  6. java生成验证码图片中仅有线条_java生成验证码步骤归纳总结

    1.serialVersionUID private static final long serialVersionUID = -8501285780349046114L; Java的序列化机制是通过 ...

  7. python3.6程序_python3.6如何生成exe程序

    PyInstaller的原理简介 PyInstaller其实就是把python解析器和你自己的脚本打包成一个可执行的文件,和编译成真正的机器码完全是两回事,所以千万不要指 望成打包成一个可执行文件会提 ...

  8. dev 命令行参数调用_云开发·云调用生成小程序码

    小程序云开发已经支持云调用,开放了很多接口,一直想要的获取小程序码也支持了.这下轻量的小程序也可以有自定义小程序码的功能. 1. 需求 获得一个带参数的小程序码,传播出去以后,用户扫码进入指定页面,根 ...

  9. J2EE如何生成验证码图片和点击刷新验证码

    验证码图片生成步骤 创建BufferedImage对象. 获取BufferedImage的画笔,即调用getGraphics()方法获取Graphics对象. 调用Graphics对象的setColo ...

  10. LabVIEW生成应用程序(exe)和安装程序(installer)

    目录 1.生成应用程序(exe) 2.生成安装程序(installer) 使用LabVIEW编写好的程序最后往往需要将程序拿到目标电脑上去运行,如何将程序从开发电脑上移植到目标电脑上呢?有两种方法: ...

最新文章

  1. java io字符输出流_【Java的IO流之文件字符输入输出流 25】
  2. java开头流程_【java读书笔记】——java开篇宏观把控 + HelloWorld
  3. 探索 ConcurrentHashMap 高并发性的实现机制--转
  4. access2013数据库实验笔记_医学科研实验基础知识笔记(十):甲基化
  5. graph theory important questions
  6. 初识Mysql(part6)--我需要知道的4条Mysql语句之利用通配符过滤
  7. 在工作或学习中要留出喝茶的时间
  8. linux 工业 网络协议,简单了解Linux TCP/IP协议栈
  9. 如何摆脱工具类【转载】
  10. struts2 中 constant标签
  11. java mysql时间格式化字符串_java将日期时间字符串转成日期插入到oracle的date字段...
  12. 1546: 回形取数
  13. 11款超5000星 后台管理模板, 总有一款适合你!
  14. Java学习资料的汇总
  15. Learning to Generalize:Meta-Learning for Domain Geralization 深度理解(公式详细推导,包含二阶导)
  16. 分享5个宝藏文字转语音配音软件,错过太可惜
  17. cmyk列印颜色_列印
  18. java高性能rpc,企业级rpc,zk调度,负载均衡,泛化调用一体的rpc服务框架
  19. 智慧医院新系统架构设计与建设
  20. May 18:PHP 函数

热门文章

  1. lib so 中查找函数
  2. 回文后缀(suffix)
  3. js识别用户设备是移动端手机时跳转到手机网站
  4. iOS 开发中常见的设计模式
  5. 三角函数的正交性为什么要用积分表示
  6. C#使用结构来传递多个参数
  7. SQL重复记录处理(查找,过滤,删除)
  8. 【Paper】AAAI 2020 故事生成模型 之 角色一致性
  9. 【小知识】Softmax函数与交叉熵
  10. 【为书豪相亲】单身小姐姐你在哪里,我是书豪,我在等你