php图像验证代码
<?php session_start(); header("content-type: image/png"); $str = "的一是在了不和有大这主中人上为们地个用工时要动国产以我到绳穷塘燥泡袋朗喂铝软渠颗惯贸粪综墙趋彼届墨碍启逆卸航雾冠丙街莱"; $imgwidth = 110; $imgheight = 24; $authimg = imagecreate($imgwidth,$imgheight); $bgcolor = imagecolorallocate($authimg,255,255,255); $fontfile = "wrzc_net.ttf"; $white=imagecolorallocate($authimg,234,185,95); imagearc($authimg, 150, 8, 20, 20, 75, 170, $white); imagearc($authimg, 100, 7,50, 22, 75, 175, $white); imageline($authimg,20,20,180,30,$white); imageline($authimg,20,18,170,50,$white); imageline($authimg,25,50,80,50,$white); $noise_num = 100; $line_num = 5; imagecolorallocate($authimg,0xff,0xff,0xff); $rectangle_color=imagecolorallocate($authimg,0xaa,0xaa,0xaa); $noise_color=imagecolorallocate($authimg,0x33,0x33,0x33); $font_color=imagecolorallocate($authimg,0x00,0x00,0x00); $line_color=imagecolorallocate($authimg,0x00,0x00,0x00); for($i=0;$i<$noise_num;$i++){ imagesetpixel($authimg,mt_rand(0,$imgwidth),mt_rand(0,$imgheight),$noise_color); } for($i=0;$i<$line_num;$i++){ imageline($authimg,mt_rand(0,$imgwidth),mt_rand(0,$imgheight),mt_rand(0,$imgwidth),mt_rand(0,$imgheight),$line_color); }//开源代码phprm.com $randnum=rand(0,strlen($str)-4); if($randnum%2)$randnum+=1; $str = substr($str,$randnum,8); $_session['supdesverify'] = $str; $str = iconv("gb2312","utf-8",$str); imagettftext($authimg, 20, 0, 0, 21, $font_color, $fontfile, $str); imagepng($authimg); imagedestroy($authimg);
教程链接:http://www.phprm.com/tuxiang/fs4437.html
随意转载~但请保留教程地址★