圖形驗證碼
雖然自己站內沒有放類似的圖形驗證碼,不過還是要稍微研究一下才行。
<?php
	//檔案類型
	header("Content-type: image/PNG");
	//產生亂數種子
	srand((double)microtime()*1000000);
	//載入建立背景圖
	$im = imagecreatefromjpeg ("../images/megull/actor000.jpg");
	//或是使用imagecreate()建立
	//$im = imagecreate(180, 180);
	
	//設定顏色(0~255,0~255,0~255)
	$backColor = imagecolorallocate($im, 225, 225, 225);
	$fontColor = imagecolorallocate($im, 51, 51, 51);
	$blueColor = imagecolorallocate ($im, 66, 180, 255); 
	
	//產生文字
	$text = "Megull"; 
	
	//隨機產生文字數字
	$text_array = array("a","b","c","d","e");
	$randText = $text_array[rand(0,4)].rand(1,9).rand(1,9) ;
	
	//畫出填滿底色(圖形,初始x,初始y,顏色)
	imagefill($im, 0, 0, $backColor);
	//畫水平文字(圖形,(1~4,5嵌入字體,初始x,初始y,文字,顏色)
	imagestring($im, 5, 80, 60, $text, $fontColor);	
	imagestring($im, 5, 80, 80, $randText, $fontColor);
	//畫多邊形(圖形,array(座標1,座標2,),幾邊型,顏色)
	imagepolygon($im, array(20,60,40,100,40,150,10,180),4,$blueColor);	
	//畫圓弧形(圖形,初始x,初始y,長,寬,角度初始,角度結束,顏色)
	imagearc($im, 100, 100, 80, 40, 0, 270, $blueColor);		
	//畫矩形(圖型,初始x,初始y,長,寬,顏色)
	imagerectangle ($im, 5, 5, 30, 30, $blueColor);
	//畫線(圖型,初始x,初始y,結束x,結束y,顏色)
	imageline ($im, 10, 150, 100, 150, $blueColor);
	//畫點(圖型,初始x,初始y,顏色)
	for($i = 0; $i < 200; $i++) {
		$point = imagecolorallocate($im, 66, 180, 255-$i);
		imagesetpixel($im, rand(1,180) , rand(1,180), $point);
	}
	//輸出檔案
	imagepng($im);
	//結束清除圖形繪製
	imagedestroy($im);
	
	//製作驗證碼時使用
	//session_start();
	//$_SESSION['checkCode'] = $randText;
?>
 
                    Link is http://megull.idv.tw/MegullWorld/php/圖形驗證碼/Tags is phpPush to Create at 2011-06-28 23:41:57, Revise at 2011-08-20 16:04:39