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

最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php圖像驗(yàn)證碼生成代碼

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

本文實(shí)例為大家分享了php封裝的一個(gè)生成圖像驗(yàn)證碼,供大家參考,具體內(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)輸出四個(gè)數(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個(gè)像素點(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);//將類實(shí)例化為對(duì)象 
  $image->show();//調(diào)用函數(shù) 
?> 

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

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

相關(guān)文章

最新評(píng)論

黎城县| 普宁市| 甘谷县| 鹰潭市| 皋兰县| 筠连县| 新田县| 逊克县| 宣化县| 射洪县| 霍山县| 襄汾县| 渭南市| 乐陵市| 华坪县| 海伦市| 睢宁县| 永定县| 大渡口区| 丰顺县| 兴安盟| 紫云| 永安市| 景洪市| 手机| 金湖县| 博罗县| 双鸭山市| 丽江市| 桂东县| 阳高县| 涿鹿县| 大悟县| 新蔡县| 丰县| 旬邑县| 剑川县| 香港| 汾西县| 水城县| 东阿县|