PHP使用GD库生成图像验证码

来源:互联网 发布:银川市大数据管理局 编辑:程序博客网 时间:2024/05/21 07:11
<?php$img = imagecreatetruecolor(100, 40);$black = imagecolorallocate($img, 0x00, 0x00, 0x00);$green = imagecolorallocate($img, 0x00, 0xFF, 0x00);$white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF);imagefill($img,0,0,$white);//生成随机的验证码$code = '';for($i = 0; $i < 4; $i++) {    $code .= rand(0, 9);}imagestring($img, 5, 10, 10, $code, $black);//加入噪点干扰for($i=0;$i<50;$i++) {  imagesetpixel($img, rand(0, 100) , rand(0, 100) , $black);   imagesetpixel($img, rand(0, 100) , rand(0, 100) , $green);}//输出验证码header("content-type: image/png");imagepng($img);imagedestroy($img);

0 0
原创粉丝点击