很多站长朋友们都不太清楚php绘制健康码,今天小编就来给大家整理php绘制健康码,希望对各位有所帮助,具体内容如下:
本文目录一览: 1、 php的图片验证码代码 2、 php qrcode怎么生成一维码 3、 PHP滑动拼图验证码的图片是怎样生成的 4、 健康码有没有使用嵌入式技术? 5、 常规码怎么弄 php的图片验证码代码这个是phpcms的验证码,经过十几万个网站经验的,非常好用
<?php
session_start();
$enablegd = 1;
//判断图像处理函数是否存在
$funcs = array('imagecreatetruecolor','imagecolorallocate','imagefill','imagestring','imageline','imagerotate','imagedestroy','imagecolorallocatealpha','imageellipse','imagepng');
foreach($funcs as $func)
{
if(!function_exists($func))
{
$enablegd = 0;
break;
}
}
ob_clean(); //清理缓冲
if($enablegd)
{
//create captcha
$consts = 'cdfgkmnpqrstwxyz23456';
$vowels = 'aek23456789';
for ($x = 0; $x < 6; $x++)
{
$const[$x] = substr($consts, mt_rand(0,strlen($consts)-1),1); //获取$consts中的一个随机数
$vow[$x] = substr($vowels, mt_rand(0,strlen($vowels)-1),1); //获取$vowels中的一个随机数
}
$radomstring = $const[0] . $vow[0] .$const[2] . $const[1] . $vow[1] . $const[3] . $vow[3] . $const[4];
$_SESSION['checkcode'] = $string = substr($radomstring,0,4); //显示4个字符
$imageX = strlen($radomstring)*8; //图像的宽
$imageY = 20; //图像的高
$im = imagecreatetruecolor($imageX,$imageY); //新建一个真彩色图像
//creates two variables to store color
$background = imagecolorallocate($im, rand(180, 250), rand(180, 250), rand(180, 250)); //背景色
$foregroundArr = array(imagecolorallocate($im, rand(0, 20), rand(0, 20), rand(0, 20)),
imagecolorallocate($im, rand(0, 20), rand(0, 10), rand(245, 255)),
imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(0, 10)),
imagecolorallocate($im, rand(245, 255), rand(0, 20), rand(245, 255))
);
$foreground2 = imagecolorallocatealpha($im, rand(20, 100), rand(20, 100), rand(20, 100),80); //分配颜色并说明透明度
$middleground = imagecolorallocate($im, rand(200, 160), rand(200, 160), rand(200, 160)); //中间背景
$middleground2 = imagecolorallocatealpha($im, rand(180, 140), rand(180, 140), rand(180, 140),80); //中间背景2
//与左上角的颜色相同的都会被填充
imagefill($im, 0, 0, imagecolorallocate($im, 250, 253, 254));
//往图像上写入文字
imagettftext($im, 12, rand(30, -30), 5, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/ALGER.TTF', $string[0]);
imagettftext($im, 12, rand(50, -50), 20, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/ARIALNI.TTF', $string[1]);
imagettftext($im, 12, rand(50, -50), 35, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/ALGER.TTF', $string[2]);
imagettftext($im, 12, rand(30, -30), 50, rand(14, 16), $foregroundArr[rand(0,3)], XINCHENG_ROOT.'include/fonts/arial.ttf', $string[3]);
//画边框
$border = imagecolorallocate($im, 133, 153, 193);
imagerectangle($im, 0, 0, $imageX - 1, $imageY - 1, $border);
//画一些随机出现的点
$pointcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
for ($i=0;$i<80;$i++)
{
imagesetpixel($im,rand(2,$imageX-2),rand(2,$imageX-2),$pointcol);
}
//画随机出现的线
for ($x=0; $x<9;$x++)
{
if(mt_rand(0,$x)%2==0)
{
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999)); //画线
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground2); //画椭圆
}
else
{
imageline($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 999999));
imageellipse($im, rand(0, 120), rand(0, 120), rand(0, 120), rand(0, 120), $middleground);
}
}
//output to browser
header("content-type:image/png\r\n");
imagepng($im);
imagedestroy($im);
}
else
{
$files = glob(XINCHENG_ROOT.'images/checkcode/*.jpg');
if(!is_array($files)) die('请检查文件目录完整性:/images/checkcode/');
$checkcodefile = $files[rand(0, count($files)-1)]; //随机其中一个文件
$_SESSION['checkcode'] = substr(basename($checkcodefile), 0, 4); //获得文件名
header("content-type:image/jpeg\r\n");
include $checkcodefile;
}
?>
php qrcode怎么生成一维码生成一维码,不是有那个功能吗?条码生成软件都有的,直接点击绘制一维码的选项
PHP滑动拼图验证码的图片是怎样生成的1 如果放在项目中用,验证码图片希望可以是接口返回。ImageView以及其子类支持花式加载图片。
2 继承自ImageView,绘制图片本身不用我们干预,也不用我们操心scaleType,节省很多工作。
* 在onSizeChanged()方法中生成 和 控件宽高相关的属性值:
1 初始化时随机生成验证码区域起点
2 生成验证码区域Path
3 生成滑块Bitmap
* onDraw()时,依次绘制:
1 验证码阴影
2 滑块
健康码有没有使用嵌入式技术?嵌入式技术是20年前提出来的,手机是近几年新生嵌入式设备。广义上讲,手持的电子计算机系统都是嵌入式设备。以及智能仪表,汽车电动车控制器,都叫嵌入式。设计健康吗不需要会制造手机,用到的是软件技术,应该是java php 浏览器 android ios 数据库系统等技术的综合项目。嵌入式一般指硬件系统,而健康吗使软件。你看看吧
常规码怎么弄第一步:创建画布
创建画布有两个函数:
imagecreate(width,height);
作用:创建画布,只能有256种颜色!
imagecreatetruecolor(width,height);
作用:创建真彩色画布
什么叫真彩色?24位真彩色
三原色:rgb
red:0-255 刚好可以使用一个字节(8个bit位)来存储
green:0-255 刚好可以使用一个字节(8个bit位)来存储
blue:0-255 刚好可以使用一个字节(8个bit位)来存储
所以,一共可以表示28*28*28 = 224种颜色!
得到了一个画布资源!
第二步:为画布创建一种颜色
注意:
所有需要在画布上呈现的颜色,都必须事先分配给画布!
通过一个函数来实现:
imagecolorallocate(image,red,green,blue);
其中:img是一个画布资源,后面的rgb代表一个颜色!
该函数的作用就是得到一个颜色的句柄(是一个int的数值)
第三步:绘制文字(画画)
文字又可以分成两种:
一种是简单的文字,ASCII码,另一种是复杂的文字,比如中文!
绘制文字需要使用一个函数:
imagestring(img,size,x,y,string,color);
其中:
img:画布资源
size:文件的大小,这里只能是1-5,并且5是最大的
x,y:起始坐标
string:文字内容
color:是颜色句柄
第四步:输出或者保存图片
输出图片
此时,需要使用函数:imagepng|imagejpeg|imagegif
imagepng(img)
此时,img就是画布资源!
此时,我们应该要去服务器在作出响应的时候告诉浏览器,反馈给浏览器的数据是一个图片而不是html文件!
此时,我们需要在输出图片之前使用header函数来设置响应头信息:
Header(“content-type:image/png”)
保存图片
还是使用imagepng这种系列的函数,只是多了第二个参数,就是一个保存的路径
需要特别注意的一个地方:
在使用imagepng函数输出图片的时候,前面不能有任何的输出!
所以,为了避免项目中出现类似的问题,可以在输出图片之间,先清理数据缓冲区:
这个时候,就需要使用一个函数ob_clean来完成!
建议,无论在任何时候,在输出图片之间都使用ob_clean来清理数据缓冲区!
产生随机验证码字符串
第一步:拼凑出一个数组(包含大小写字母和数字)
基本策略:使用两个函数来完成
range(‘a’,’z’);
array_merge: 如$arr=array_merge(range('a','z'),range('A','Z'),range(0, 9));
第二步:打乱该数组
使用shuffle函数:
第三步:使用array_rand随机抽取若干个数组的下标值
第四步:根据获得的下标遍历获得原数组的值
制作验证码
需要使用的函数
填充背景
使用imagefill函数
imagefill(img,x,y,color);
其中:
img:画布资源
x,y:坐标点
color:要填充的颜色句柄
填充的意思就是填充一块连续的颜色相同的区域!
添加干扰线
添加干扰线的本质就是绘制直线!
需要使用imageline(img,x1,y1,x2,y2,color)
其中:
img:画布资源
x1,y1,x2,y2:两点的坐标
color:颜色句柄
添加噪点(干扰点)
所谓的一个噪点就是一个干扰点,一个干扰点就是一个像素!
需要使用imagesetpixel(img,x,y,color);
代码实现
<?php
//1.创建画布
$img=imagecreatetruecolor(170, 40);
//2.填充背景色
//2.1创建背景的颜色
$backcolor=imagecolorallocate($img,mt_rand(180,255), mt_rand(180,255), mt_rand(180,255));
//2.2填充背景
imagefill($img, 0, 0, $backcolor);
//3.产生随机验证码字符串
//3.1利用arrar_merge和range函数拼凑出一个数组
$arr=array_merge(range('a','z'),range('A','Z'),range(0, 9));
//3.2打乱数组
shuffle($arr);
//3.3随机抽取若干个数组的下标值
$rand_key=array_rand($arr,4);
//3.4根据获得的下标遍历获得原数组的值
$str='';
foreach ($rand_key as $value) {
$str.=$arr[$value];//
}
//8.将验证码字符串保存到session中
session_start();
$_SESSION['captcha']=$str;
//4.将验证码字符串写到图片上
//4.1计算字符间距
$span=ceil(170/(4+1));
for($i=1;$i<=4;$i++){
$stringcolor=imagecolorallocate($img,mt_rand(0,100), mt_rand(0,100), mt_rand(0,100));
imagestring($img,5, $i*$span, 10, $str[$i-1], $stringcolor);//水平地画一行字符串
}
//5.填加干扰线
for($i=1;$i<=8;$i++){
//5.1创建干扰线颜色
$linecolor=imagecolorallocate($img,mt_rand(100,180), mt_rand(100,180), mt_rand(100,180));
imageline($img,mt_rand(0,169), mt_rand(0,169), mt_rand(0,39), mt_rand(0,39), $linecolor);
}
//6.添加噪点(干扰点)
for($i=1;$i<=170*40*0.05;$i++){
$pixelcolor=imagecolorallocate($img,mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
imagesetpixel($img,mt_rand(0,169), mt_rand(0,39), $pixelcolor);
}
//7.输出图片
//设置响应头信息
header("content-type:image/png");
//清理数据缓存区
ob_clean();
//输出图片
imagepng($img);
//保存图片
关于php绘制健康码的介绍到此就结束了,不知道本篇文章是否对您有帮助呢?如果你还想了解更多此类信息,记得收藏关注本站,我们会不定期更新哦。
查看更多关于php绘制健康码 php源码怎么搭建网站的详细内容...