PHP圖形驗證碼程序_第1頁
PHP圖形驗證碼程序_第2頁
PHP圖形驗證碼程序_第3頁
PHP圖形驗證碼程序_第4頁
PHP圖形驗證碼程序_第5頁
已閱讀5頁,還剩5頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、PHP圖形驗證碼程序最近經(jīng)常有人問我這個Blog中的圖形驗證碼是如何做的.下面是這個php圖形驗證碼的源程序.歡迎指正.class.image.phpclass ImagePRivate $img;private $width;private $height;private $color;private $font;private $mime="image/jpeg"/* 1,GIF 2,JPEG 3,PNG */private $type=2;private $angle=0;private $text;private $textW;private $textH;priv

2、ate $size=5;private $tcolor;function _construct($w="100", $h="50"$this->width=$w;$this->height=$h;function create( if ($this->type != 1 && function_exists('imagecreatetruecolor' / 本函數(shù)不能用于GIF 文件格式/ 本函數(shù)需要GD 2.0.1 或更高版本。/ 返回一個圖像標(biāo)識符,代表了一幅大小為x_size 和y_size 的黑色

3、圖像$this->img=imagecreatetruecolor($this->width,$this->height;else $this->img=imagecreate($this->width,$this->height;/* 1=GIF 2=JPG* 3=PNG*/function createFromFile($f$imgInfo=getimagesize($f;$this->type=$imgInfo2;switch($this->typecase 1:$this->loadGifFile($f;break;case 2:$

4、this->loadJpegFile($f;break;case 3:$this->loadPngFile($f;break;default:die("This Image Type Not Support loadimage !"exit(;function loadGifFile($f/ 1.6 - 2.0.28/二者之間版本的GD 庫時本函數(shù)不可用$this->img=imagecreatefromgif($f or die("Load Gif picture error!" ;$this->width=imagesx($t

5、his->img;$this->height=imagesy($this->img;$this->mime="image/gif"$this->type=1;function loadJpegFile($f/JPEG 支持僅在PHP 與GD-1.8 或更高版本一起編譯時可用$this->img=imagecreatefromjpeg($f or die("Load Jpeg picture error!" ;$this->width=imagesx($this->img;$this->height=i

6、magesy($this->img;$this->mime="image/jpeg"$this->type=2;function loadPngFile($f$this->img=imagecreatefrompng($f or die("Load Png picture error!" ;$this->width=imagesx($this->img;$this->height=imagesy($this->img;$this->mime="image/png"$this->

7、;type=3;function setBackgroundColor($r, $g, $b# 用color 顏色填充了的矩形# 其左上角坐標(biāo)為x1,y1# 右下角坐標(biāo)為x2,y2# 0, 0 是圖像的最左上角$color =imagecolorallocate($this->img, $r, $g, $b;return imagefilledrectangle($this->img, 0, 0, $this->width, $this->height, $color; function setColor($r, $g, $b$this->color=imagec

8、olorallocate($this->img, $r, $g, $b;return (-1 = $this->color ? (false : ($this->color;function setTextColor($r, $g, $b$this->tcolor=imagecolorallocate($this->img, $r, $g, $b;return (-1 = $this->tcolor ? (false : ($this->tcolor;function setText($t$this->text=$t;function water

9、Mark($r, $g, $b, $alpha$this->tcolor=imagecolorclosestalpha($this->img, $r, $g, $b, $alpha;function setFontFile($f$this->font=$f;function addTrueTypeText($xoffset,$yoffset#$x=( ( $this->width - $this->textW - 10 > 0 ? ($this->width - $this->textW - 10 : (0 ;#$y=( ( $this->

10、height-10 > 0 ? ($this->height-10 : ($this->height;/ 用TrueType 字體向圖像寫入文本/ *x,y 坐標(biāo)是字符串左下角坐標(biāo),整幅圖像的左上角為0,0imagettftext($this->img,$this->size,$this->angle,$xoffset,$yoffset,$this->tcolor,$this->font,$this->text;function addText( / 用color 顏色將字符串s 畫到image/ *x,y 坐標(biāo)是字符串左上角坐標(biāo),整幅圖像

11、的左上角為0,0/ 如果font 是1,2,3,4 或5,則使用內(nèi)置字體。imagestring ($this->img, $font, $x, $y, $this->text, $this->tcolor;function setSize($s$this->size=$s;function setAngle($a$this->angle=$a;function setWidth($w$this->width=$w;function setHeight($h$this->height=$h;function getWidth(return $this-

12、>width;function getHeight(return $this->height;function setPixel($x,$y,$colorreturn imagesetpixel($this->img, $x, $y, $color;function setLine($x1,$y1,$x2,$y2,$colorreturn imageline($this->img, $x1, $y1, $x2, $y2, $color; function createImageFile($f="default"if( !empty($f switch

13、($this->typecase 1:imagegif($this->img, $f.".gif",80;break;case 2:imagejpeg($this->img, $f.".jpg" , 80;break;case 3:imagepng($this->img, $f.".png", 80;break;default:die("This Image Type Not Support create !"exit(;imagedestroy($this->img;function

14、 show(header("Content-type: ".$this->mime; switch($this->type case 1: imagegif($this->img; break; case 2: imagejpeg($this->img; break; case 3: imagepng($this->img; break; default: die("This Image Type Not Support show !" exit(; imagedestroy($this->img; /* Zoom O

15、ut Picture */ function roomOut($maxW, $maxH $WW=($maxW and ($this->width > $maxW; $HH=($maxH and ($this->height > $maxH; if($WW or $HH if($WW $wRatio =$maxW / $this->width; $wResize=true; if($HH $hRatio =$maxH / $this->height; $hResize=true; if($wResize and $hResize if($wRatio <

16、 $hRatio $ratio=$wRatio; else $ratio=$hRatio; elseif($wResize $ratio=$wRatio; elseif($hResize $ratio=$hRatio; else $ratio=1; $newWidth=$this->width * $ratio; $newHeight=$this->height * $ratio; if(function_exists("imagecopyresampled" $newimg=imagecreatetruecolor($newWidth, $newHeight;

17、 imagecopyresampled($newimg, $this->img, 0, 0, 0, 0, $newWidth, $newHeight, $this->width, $this->height; else $newimg=imagecreate($newWidth, $newHeight; imagecopyresized($newimg, $this->img, 0, 0, 0, 0, $newWidth, $newHeight, $this->width, $this->height; $this->img=$newimg; $thi

18、s->width= $newWidth; $this->height=$newHeight; imgverifycode.php create(; $im->setBackgroundColor( mt_rand(0xdd,0xff, mt_rand(0xdd,0xff, mt_rand(0xdd,0xff ; $im->setSize( $s ; for($i=$p; $i<$w-$p; $i=$i+$s+$p $char = $strmt_rand(0,$len; $code = $code.$char; $im->setFontFile($CFG->dirroot.'/font/'.mt_rand(2,5.'.ttf' $im->setText( $char ; $im->setAngle( mt_rand(-$a,$a ; $im

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論