最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

一漂亮的PHP圖片驗(yàn)證碼實(shí)例

 更新時(shí)間:2014年03月21日 09:51:14   作者:  
在網(wǎng)上看到一個(gè)圖片驗(yàn)證碼,挻漂亮的,但是取回來發(fā)現(xiàn),好像有點(diǎn)小問題,還是改為自己的口味吧,很多時(shí)候,如果無法使用,應(yīng)該是字體的問題。程序所用的字體win7 自帶的,需要上傳到web目錄

一、顯示效果

二、代碼如下

復(fù)制代碼 代碼如下:
/*
 *  @Author fy
 */

$imgwidth =100; //圖片寬度
$imgheight =40; //圖片高度
$codelen =4; //驗(yàn)證碼長度
$fontsize =20; //字體大小
$charset = 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789';
$font = 'Fonts/segoesc.ttf';

$im=imagecreatetruecolor($imgwidth,$imgheight);

$while=imageColorAllocate($im,255,255,255);
imagefill($im,0,0,$while); //填充圖像

//取得字符串
$authstr='';
$_len = strlen($charset)-1;
for ($i=0;$i<$codelen;$i++) {
 $authstr .= $charset[mt_rand(0,$_len)];
}

session_start();
$_SESSION['scode']=strtolower($authstr);//全部轉(zhuǎn)為小寫,主要是為了不區(qū)分大小寫

//隨機(jī)畫點(diǎn),已經(jīng)改為劃星星了
for ($i=0;$i<$imgwidth;$i++){
    $randcolor=imageColorallocate($im,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
 imagestring($im,mt_rand(1,5), mt_rand(0,$imgwidth),mt_rand(0,$imgheight), '*',$randcolor);
    //imagesetpixel($im,mt_rand(0,$imgwidth),mt_rand(0,$imgheight),$randcolor);
}
//隨機(jī)畫線,線條數(shù)量=字符數(shù)量(隨便)
for($i=0;$i<$codelen;$i++)

 $randcolor=imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
 imageline($im,0,mt_rand(0,$imgheight),$imgwidth,mt_rand(0,$imgheight),$randcolor);
}

$_x=intval($imgwidth/$codelen); //計(jì)算字符距離
$_y=intval($imgheight*0.7); //字符顯示在圖片70%的位置
for($i=0;$i<strlen($authstr);$i++){

 $randcolor=imagecolorallocate($im,mt_rand(0,150),mt_rand(0,150),mt_rand(0,150));
 //imagestring($im,5,$j,5,$imgstr[$i],$color3);
 // imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
 imagettftext($im,$fontsize,mt_rand(-30,30),$i*$_x+3,$_y,$randcolor,$font,$authstr[$i]);

}

//生成圖像
header("content-type:image/PNG");
imagePNG($im);
imageDestroy($im);


 

相關(guān)文章

最新評(píng)論

娱乐| 垣曲县| 沂源县| 遵化市| 营山县| 鱼台县| 唐山市| 桑植县| 临沧市| 双流县| 桂林市| 陆川县| 阿荣旗| 大化| 云和县| 德安县| 桃源县| 曲水县| 余庆县| 金沙县| 伊金霍洛旗| 辉南县| 高碑店市| 杭州市| 湾仔区| 永登县| 那曲县| 武冈市| 沽源县| 汕尾市| 绍兴县| 富平县| 常山县| 璧山县| 梨树县| 昭通市| 连云港市| 呼图壁县| 安仁县| 东山县| 井冈山市|