PHP基礎------GD庫繪製驗證碼

來源:互聯網
上載者:User

標籤:

<?php一:GD函數庫    1.函數:        imagecreate(width,height) 建立了基於調色盤的映像        imagecreatetruecolor(width,height) 建立基於真色彩的映像        header("content-type:image/圖片格式");        圖片格式:gif jpeg png        imagegif(image)輸出映像        imagedestroy(image)銷毀映像        imagestring(image, font, x, y, string, color)寫入字串        imagecolorallocate(image, red, green, blue)為映像分配顏色        imagettftext(                    image, //映像                    size, //文字大小 單位px                    angle, //傾斜的角度                    x, //文字起點的座標                    y, //文字起點的座標                    color, //顏色                    fontfile, //ttf檔案的位置                    text//常值內容            )        imagefilledrectangle(image, x1, y1, x2, y2, color)繪製一個矩形        imagesetpixel(image, x, y, color)繪製單獨的像素點        imageline(image, x1, y1, x2, y2, color)繪製一個線段?>

驗證碼案例:

<?phpheader("content-type:image/gif");//驗證碼寬高$width = "150";$height = "60";//建立畫布$image = imagecreatetruecolor($width, $height);//分配顏色$color = imagecolorallocate($image, 255, 255, 255);//文字顏色$sizeColor = imagecolorallocate($image, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));//填充畫布imagefilledrectangle($image, 0, 0, 150, 60, $color);//驗證碼文本$num = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";$checkStr = null;//驗證碼的位元for ($i=0; $i < 4; $i++) {     $checkStr = $checkStr.$num[rand(0,35)];}//寫入文本imagettftext($image, 25, mt_rand(-5,5), 20, 30, $sizeColor, "segoeprb.ttf", $checkStr); //繪製噪點for ($i=0; $i <100 ; $i++) {     imagesetpixel($image, mt_rand(0,150), mt_rand(0,60),$sizeColor);}//繪製幹擾線for ($i=0; $i < 4; $i++) {     imageline($image,mt_rand(0,150), mt_rand(0,60), mt_rand(0,150), mt_rand(0,60), $sizeColor);}//輸出映像imagegif($image);//銷毀映像imagedestroy($image);?>

 

PHP基礎------GD庫繪製驗證碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.