標籤:
<?php $i=imagecreatetruecolor(100, 30);$iColor=imagecolorallocate($i, 240, 240, 240);imagefill($i, 0, 0, $iColor);$str="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPSDFGHJKLZXCVBNM";$nStr=str_shuffle($str);$fourStr=substr($nStr, 0,4);for ($j=0; $j < strlen($fourStr); $j++) { $s=substr($fourStr, $j,1); //隨機顏色,盡量不要太淺(和底色白色有差別) $fColor=imagecolorallocate($i, mt_rand(0,150), mt_rand(0,150), mt_rand(0,150)); //隨機傾斜 $angle=mt_rand(0,45); $x=8+$j*25; $y=25; //SIMYOU.TTF字型檔可以在C:\WINDOWS\Fonts下找到,多個字型也可以添加到一個數組中,然後隨機提取 imagefttext($i, 20, $angle, $x, $y, $fColor, "SIMYOU.TTF", $s);}//添加幹擾線 (4條幹擾線)for ($j=0; $j < 4; $j++) { $lColor=imagecolorallocate($i, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); $x1=mt_rand(0,100); $y1=mt_rand(0,30); $x2=mt_rand(0,100); $y2=mt_rand(0,30); imageline($i, $x1, $y1, $x2, $y2, $lColor);}//加幹擾點(200個幹擾點)for ($j=0; $j < 200; $j++) { $pColor=imagecolorallocate($i, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); $x=mt_rand(0,100); $y=mt_rand(0,30); imagesetpixel($i, $x, $y, $pColor);}header("content-type:image/png");imagepng($i);?>
php簡單產生驗證碼圖片