因为是练习,写的有点乱。
$fsize = 4;
$code_bit = 10;
$width = (($fsize<5?$fsize:5)+4) * $code_bit+10; //$fsize+4 4为调整数字
$height = 30;
//生成随机字符串 方法一
//$chars = "0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ";
//$code = '';
//for($k=0;$k<$code_bit;$k++){
// $i = mt_rand(0,34);
// $code.=$chars[$i];
//}
//生成随机字符串 方法二
$code = '';
for($c = 0;$c < $code_bit;$c++){
$count = mt_rand(0,1);
switch($count){
case 0 : $rand_code = mt_rand(48,57); break; //数字
case 1 : $rand_code = mt_rand(65,90); break; //大写字母
//case 2 : $rand_code = mt_rand(97,122); break; //小写字母
}
$code.=sprintf("%c",$rand_code);
}
//$image = imagecreate(300,200);
$image = imagecreatetruecolor($width,$height);
//$image = imagecreatefromgif('xiaohai.gif');
header('content-type:image/png');
$backgroud = imagecolorallocate($image,180,20,20);
$white = imagecolorallocate($image,255,255,255);
$border = imagecolorallocate($image,0,0,0);
$green = imagecolorallocate($image,0,255,0);
$gray = imagecolorallocate($image,100,100,100);
imagefill($image,0,0,$backgroud);
//输出字符串到图片 整齐样式
//imagestring($image,$fsize,5,floor(($height-($fsize<5?$fsize:5)-9)/2),$code,$white); //9为调整数字
//输出字符串到图片 单字符输出
for($c = 0;$c < $code_bit;$c++){
$x = (($width-10)/$code_bit)*$c+5;
$y = mt_rand(5,$height-18);
imagechar($image,$fsize,$x,$y,$code[$c],$white);
}
//中文验证
//$text = iconv("GB2312","UTF-8","测试中文");
//$font = "simhei.ttf";
//imagettftext($image,12,5,7,21,$gray,$font,$text);
//imagettftext($image,12,5,5,20,$white,$font,$text);
//imagestring($image,$fsize,5,5,$text,$white);
imagerectangle($image,0,0,$width-1,$height-1,$border);
//生成杂点
for($c=0;$c<100;$c++){
$color = imagecolorallocate($image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($image,mt_rand(1,$width-2),mt_rand(1,$height-2),$color);
}
//生成线条
for($c=0;$c<1;$c++){
$color = imagecolorallocate($image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imageline($image,mt_rand(1,$width-2),mt_rand(1,$height-2),mt_rand(1,$width-2),mt_rand(1,$height-2),$color);
}
//imageline($image,15,23,56,10,$green);
//生成弧线
for($c=0;$c<1;$c++){
$color = imagecolorallocate($image,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagearc($image,mt_rand(1,$width-2),mt_rand(1,$height-2),mt_rand(1,$width-2),mt_rand(1,$height-2),mt_rand(0,360),mt_rand(0,360),$color);
}
//imagearc($image,30,10,100,20,20,80,$green);
imagepng($image);
//imagegif($image);
imagedestroy($image);
分享到:
相关推荐
这里是gd2验证码直接 可以引用的必须开启gd2,有些人忘了开 会显示红叉
利用PHP中的GD库实现数字,字母,数字和字母的结合以及图片类型的验证码
PHP版验证码源代码,轻松上手,免费下载
可以通过使用GD库生成图片验证码,很好看
其实phpwind本身已经有了防止无限制登录的功能!但有人还是要,就随便改了一个!需要gd库的支持! phpwind登录验证码插件 by bg9cx
一个基于GD库的php验证码类,设置图片高度,宽度,字符个数,颜色字体,图片背景等等。
本文给大家分享的是使用php的GD库来实现验证码功能的方法和全部代码,有需要的小伙伴可以参考下
PHP加GD2加javascript做无刷新验证码
这是利用GD库生成验证码的页面 test.PHP <?php header('Content-Type:image/jpeg'); $img = imagecreatetruecolor(100, 40); $black = imagecolorallocate($img, 0x00, 0x00, 0x00); $green = ...
主要介绍了PHP基于GD2函数库实现验证码功能,简单介绍了GD2函数库的常用函数,并结合实例形式分析了php实现验证码功能相关操作技巧,需要的朋友可以参考下
分享一个基于GD库的php验证码类,设置图片高度,宽度,字符个数,颜色字体,图片背景等等。
兆易创新GD32系列单片机ALTIUM原理图库(100个)+PCB封装库(20个),可直接用于你的项目设计中。 原理图库: GD32E103CxT6 GD32E103RxT6 GD32E103TxU6 GD32E103VxT6 GD32E230CxT6 GD32E230CxW7 GD32E230FXV6 GD...
兆易GD32F1x0_Firmware_Library GD32F130G8单片机软件例程源码(10例) 一、开发说明 1、开发环境: MDK5.24a 2、标准外设库: GD32F1x0_Firmware_Library_v3.1.0 3、硬件: 技新GD32F130G8U6核心板 & GD-LINK...
本文实例讲述了PHP通过GD库实现验证码功能。分享给大家供大家参考,具体如下: 首先看看实现的效果: 具体实现: <?php /*PHP实现验证码*/ session_start();//开启会话 //创建画布 $image=imagecreatetruecolor...
Introduction:GD32F403系列MCU标准固件库,支持GD32F403 Introduction:GD32F4xx系列MCU标准固件库,支持GD32F405/GD32F407/GD32F450 Introduction:Introduction:包含三个文件,具体说明如下: 1. GigaDevice....
gd32移植freemodbus示例工程
GD32通过SPI和QSPI模式读取GD的NOR Flash,支持DMA模式,和文件系统。
Delphi调用gd库生成随机验证码演示,常用于ISAPI网站中生成网页验证码。
GD32E232_用户手册GD32E232_用户手册GD32E232_用户手册GD32E232_用户手册