介紹了php圖像驗證碼的生成代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下" />

欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php圖像驗證碼生成代碼

 更新時間:2017年06月08日 11:59:55   作者:cakin24  
這篇文章主要為大家詳細(xì)
介紹了php圖像驗證碼的生成代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了php封裝的一個生成圖像驗證碼,供大家參考,具體內(nèi)容如下

一、代碼

index..php

TestCode.php

<?php 
  class TestCode{//創(chuàng)建類名為TestCode 
   private $width; 
   private $height; 
   private $str; 
   private $im; 
   private $strColor;    
   function __construct($width,$height){ 
    $this->width=$width; 
    $this->height=$height; 
    $this->str=$_GET['code']; 
    $this->createImage(); 
   } 
   function createImage(){ 
    $this->im=imagecreate($this->width,$this->height);//創(chuàng)建畫布 
    imagecolorallocate($this->im,200,200,200);//為畫布添加顏色 
    for($i=0;$i<4;$i++){//循環(huán)輸出四個數(shù)字 
     $this->strColor=imagecolorallocate($this->im,rand(0,100),rand(0,100),rand(0,100)); 
     imagestring($this->im,rand(3,5),$this->width/4*$i+rand(5,10),rand(2,5),$this->str[$i],$this->strColor); 
    } 
    for($i=0;$i<200;$i++){//循環(huán)輸出200個像素點(diǎn) 
     $this->strColor=imagecolorallocate($this->im,rand(0,255),rand(0,255),rand(0,255)); 
     imagesetpixel($this->im,rand(0,$this->width),rand(0,$this->height),$this->strColor); 
    } 
   } 
   function show(){// 
    header('content-type:image/png');//定義輸出為圖像類型 
    imagepng($this->im);//生成圖像 
    imagedestroy($this->im);//銷毀圖像釋放內(nèi)存 
   } 
  } 
  $image=new TestCode(80,20);//將類實例化為對象 
  $image->show();//調(diào)用函數(shù) 
?> 

 二、運(yùn)行結(jié)果

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論