php簡單產生驗證碼圖片

來源:互聯網
上載者:User

標籤:

<?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簡單產生驗證碼圖片

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.