單純使用PHP腳本不借助任何外部库或图片以及字体产生动画效果的Gif验证码图片

看过discuz的,不喜欢,又是图片,又是字体的太麻烦.

而我采用的这种方法不需要额外的图片,字体或php支持库,因为我的方式是直接使用php的ord,chr等函数操作图片源码而成.

图片是由二进制代码构成的,不管是bmp还是png,jpg,gif都是如此,那么既然php可以产生不会运动的gif图,为何就不能产生可以运动的gif图呢?差异不过就是二进制代码而已,产生的过程是没什么差别的,所以根据这样的思路我写了这个类,用来生成可以运动的验证码.

当然了最根本的原因是传统的验证码别人已经可以做到使用程序进行识别了.而我这种非传统的可以有动画的验证码期待他们来识别,如果有某位高手能够做到验证码识别的时候请在此留言告诉我.

//如果要轉載本文請注明出處,免的出現版權紛爭,我不喜歡看到那種轉載了我的作品卻不注明出處的人 Seven{See7di#Gmail.com}

以下是演示效果:



源码先发一部分出来,因为很多copy一族直接复制粘贴走我的东西,连声拜拜都没有,更有甚者都不给我留一点版权信息,所以如果大家需要完整的源码,可以email我索取(see7di@gmail.com)

//如果要轉載本文請注明出處,免的出現版權紛爭,我不喜歡看到那種轉載了我的作品卻不注明出處的人 Seven{See7di#Gmail.com}

<?PHP
//    [Can be animated image verification code!] (C)2011 Seven(See7di@Gmail.com).
//    This is a freeware and you can copy it to anyone,But please don't del this message,Thank you!
//    Seven(See7di@Gmail.com)    http://hi.baidu.com/see7di/home
Class ClassGif{
    var $Pic=Array();
    var $TOP="GIF89a";
    var $LOP=0;        //Is loop[0,1]
    var $FLY=20;    //動作速度[0->]
    var $DIS=2;        //[0,1,2,3]
    var $RGB=-1;
    var $IMG=-1;

    //Gif编码.(height,width,bgcolor)
    Function ClassGif($Gh,$Gw,$Co){
        $Gh=(!$Gh)?18:$Gh;$Gw=(!$Gw)?60:$Gw;
        IF(!$Co){$Co='255|255|255';}$Co=Explode("|",$Co);

        $_T=StrtoUpper(Dechex(Mt_Rand(1,15)).Dechex(Mt_Rand(1,15)).Dechex(Mt_Rand(1,15)));
        $_SESSION['cod']=StrToLower($_T);

        $Img=Array();
        For($i=0;$i<$Gh;$i++){
            $Image=Imagecreate($Gw,$Gh);
            Imagecolorallocate($Image,$Co[0],$Co[1],$Co[2]);

            $_L1=Imagecolorallocate($Image,Rand(150,255),Rand(200,255),Rand(200,255));
            $_L2=Imagecolorallocate($Image,Rand(1,200),Rand(1,200),Rand(1,200));
            Imagestring($Image,5,Rand(-4,($Gw/2)),Rand(-3,5),Rand(10000,20000),$_L1);    //干扰
            Imagestring($Image,7,Rand(0,($Gw/2)),Rand(-3,5),$_T,$_L2);                    //內容

            ImageGif($Image);Imagedestroy($Image);
            $Img[]=ob_get_contents();OB_clean();
        }
        $this->_Gif($Img);
    }
    //實體.(Img array)
    Function _Gif($_Src){
        $this->RGB=($this->RGB>-1)?($this->RGB|($this->RGB<<8)|($this->RGB<<16)):-1;

        For($i=0;$i<Count($_Src);$i++){
            $this->Pic[]=$_Src[$i];
            For($j=(13+3*(2<<(Ord($this->Pic[$i]{10})&0x07))),$k=True;$k;$j++){
                Switch($this->Pic[$i]{$j}){
                Case "!":
                    IF((SubStr($this->Pic[$i],($j+3),8))=="NETSCAPE"){
                        Echo 'Error:Can\'t use src[',($i+1),'] to create image!';
                        Exit(0);
                    }
                    Break;
                Case ";":
                    $k=False;
                    Break;
                }
            }
        }
        $this->_Header();
        For($i=0;$i<Count($this->Pic);$i++){
            $this->_Frame($i,$this->FLY);
        }
        $this->_Footer();
        $this->_Animation();
    }

后边的代码不发了,留待真正需要的人索取..

原文地址:https://www.cnblogs.com/see7di/p/2239805.html