时间:2019-12-05 浏览量: 收藏
php创建图像验证码源码:
<?php /** * 图像验证码 * 1、生成验证码字符串 * 2、创建画布大小,填充颜色 * 3、创建杂色到画布 * 4、创建干扰线到画布 * 5、创建字符串到画布上 * 6、输出图像 */ //0-9 a-z A-Z $arr = array_merge(range(0,9),range('a','z'),range('A','Z')); //打乱数组 shuffle($arr); //从数组中从下标0开始,取出4个元素 $arrlen = array_splice($arr,0,4); //将数组转成字符串 $text = implode($arrlen); //创建画布 $width = 120; $height = 40; $image = imagecreatetruecolor($width, $height); $reccolor = imagecolorallocate($image,mt_rand(130,255),mt_rand(130,255),mt_rand(130,255)); imagefilledrectangle($image,0,0,$width,$height,$reccolor); //添加杂色到画布 for ($i=1;$i<=450;$i++) { $pixcolor = imagecolorallocate($image,mt_rand(60,160),mt_rand(60,160),mt_rand(60,160)); imagesetpixel($image,mt_rand(0,$width),mt_rand(0,$height), $pixcolor); } //将字符串写到画布 $ttfpath = dirname(__FILE__).'/arial.ttf'; $ttfcolor = imagecolorallocate($image,mt_rand(0,120),mt_rand(0,120),mt_rand(0,120)); imagettftext($image,32,0,5,35, $ttfcolor, $ttfpath, $text); //创建干扰线到画布 for ($i=1;$i<=15;$i++) { $linecolor = imagecolorallocate($image,mt_rand(30,150),mt_rand(30,150),mt_rand(30,150)); imageline($image,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width),mt_rand(0,$height),$linecolor); } //输出图像 header("Content-Type:image/png"); imagepng($image); imagedestroy($image);
RELATED RECOMMEND
2019-12-05
1、通过PHPStudy中composer工具来安装thinkphp6.0:2、执行composer安装命令 composer create-project topthink/think tp6 6.0.*-dev:3、遇到安装失败,请更新镜像地址,
2019-12-05
在php程序判断客户端是通过电脑端还是手机端访问,以下是经过测试可行的函数function isMobile() { static $is_mobile = null; null === $is_mobile &&
2019-12-05
使用Teleport Pro软件的朋友应该知道他是一个离线浏览器,而他更大的作用则是可以用来下载别人的整站,软件的功能虽然好,但是却有一个很头疼的缺点,那就是下载下来 的网页它会在图片标签内插入tppabs标签以记录该图片的原始地址。因为这个标签不是合法标签,所以普通浏览器会忽略它。如图所示:其实可以在 DreamWeaver中使用正则表达式批量清除tppabs标签. 具体写法如下: 匹配tppabs标签: \btppabs="h[^"]*" 替换为 (空) 匹配javas...
Copyright © 2012-2024 世敏网络 版权所有 闽ICP备18026760号-1 闽公网安备 35020502000640号 网站地图 Sitemap 关键词聚合