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

一漂亮的PHP圖片驗證碼實例

一、顯示效果

二、代碼如下
復制代碼 代碼如下:/*
 *  @Author fy
 */

$imgwidth =100; //圖片寬度
$imgheight =40; //圖片高度
$codelen =4; //驗證碼長度
$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);//全部轉為小寫,主要是為了不區分大小寫

//隨機畫點,已經改為劃星星了
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);
}
//隨機畫線,線條數量=字符數量(隨便)
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); //計算字符距離
$_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技術一漂亮的PHP圖片驗證碼實例,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 施甸县| 读书| 科尔| 新疆| 五华县| 金门县| 博湖县| 萨迦县| 常宁市| 宁强县| 赤壁市| 霍州市| 洞头县| 百色市| 乌拉特后旗| 密云县| 河南省| 松溪县| 临海市| 曲沃县| 左贡县| 东乌珠穆沁旗| 苍梧县| 台南县| 咸宁市| 新巴尔虎右旗| 彩票| 资中县| 沙湾县| 杨浦区| 邓州市| 青川县| 嘉善县| 安康市| 黑山县| 建德市| 高尔夫| 达日县| 疏附县| 吉安县| 雅江县|