您的位置:首页 > 其它

GD2使用图像处理技术生成验证码

2017-11-22 10:50 260 查看
一 代码

<?php
header('content-type:image/png');
srand((double) microtime() * 1000000);
$im = imagecreate(60, 20);
imagefill($im, 0, 0, imagecolorallocate($im, 200, 200, 200));        //测试代码
//$validatorCode = $_GET['code'];        //网站使用代码
$validatorCode = '1234';
imagestring($im, rand(2, 5), 10, 3, substr($validatorCode, 0, 1), imagecolorallocate($im, 0, rand(0, 255), rand(0, 255)));
imagestring($im, rand(2, 5), 20, 3, substr($validatorCode, 1, 1), imagecolorallocate($im, rand(0, 255), 0, rand(0, 255)));
imagestring($im, rand(2, 5), 30, 3, substr($validatorCode, 2, 1), imagecolorallocate($im, rand(0, 255), rand(0, 255), 0));
imagestring($im, rand(2, 5), 40, 3, substr($validatorCode, 3, 1), imagecolorallocate($im, 0, rand(0, 255), rand(0, 255)));
for ($i = 0; $i < 200; $i ++) {
imagesetpixel($im, rand() % 70, rand() % 30, imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)));
}
imagepng($im);
imagedestroy();

 

二 运行结果



 





大小: 1.7 KB

查看图片附件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: