色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

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

一、顯示效果

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

$imgwidth =100; //圖片寬度
$imgheight =40; //圖片高度
$codelen =4; //驗(yàn)證碼長(zhǎng)度
$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)為小寫(xiě),主要是為了不區(qū)分大小寫(xiě)

//隨機(jī)畫(huà)點(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ī)畫(huà)線(xiàn),線(xiàn)條數(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);


 

php技術(shù)一漂亮的PHP圖片驗(yàn)證碼實(shí)例,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 无锡市| 乌拉特后旗| 固安县| 田阳县| 惠东县| 申扎县| 阜城县| 乌海市| 仁怀市| 宁海县| 吐鲁番市| 榆树市| 清新县| 湖州市| 修水县| 石屏县| 壶关县| 望奎县| 博爱县| 磐石市| 吴川市| 新郑市| 新宁县| 潜江市| 安远县| 阿合奇县| 贵定县| 遂昌县| 临泉县| 东港市| 遂宁市| 阿勒泰市| 宁远县| 甘洛县| 安丘市| 丹阳市| 黑山县| 科技| 淮南市| 长岭县| 岫岩|