標籤:
<?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庫繪製驗證碼