偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

PHP生成GIF動(dòng)態(tài)圖片驗(yàn)證碼

開發(fā) 后端
相信很多人都想過如何用PHP生成GIF動(dòng)畫來實(shí)現(xiàn)動(dòng)態(tài)圖片驗(yàn)證碼,以下是實(shí)現(xiàn)過程。ImageCode函數(shù)通過GIFEncoder類實(shí)現(xiàn)的GIF動(dòng)畫的PHP源代碼,有興趣的朋友可以研究一下。

相信很多人都想過如何用PHP生成GIF動(dòng)畫來實(shí)現(xiàn)動(dòng)態(tài)圖片驗(yàn)證碼,以下是實(shí)現(xiàn)過程。

ImageCode函數(shù)通過GIFEncoder類實(shí)現(xiàn)的GIF動(dòng)畫的PHP源代碼,有興趣的朋友可以研究一下。

效果如圖: 點(diǎn)擊查看原圖

  1. /**  
  2.  * ImageCode 生成GIF圖片驗(yàn)證  
  3.  * @param $string 字符串  
  4.  * @param $width 寬度  
  5.  * @param $height 高度  
  6.  * */ 
  7. function ImageCode($string = ''$width = 75, $height = 25)  
  8. {  
  9.     $authstr = $string ? $string : ((time() % 2 == 0) ? mt_rand(1000, 9999) : mt_rand(10000, 99999));   
  10.       
  11.     $board_width = $width;  
  12.     $board_height = $height;  
  13.     // 生成一個(gè)32幀的GIF動(dòng)畫  
  14.     for($i = 0; $i < 32; $i++)  
  15.     {  
  16.         ob_start();  
  17.         $image = imagecreate($board_width$board_height);  
  18.         imagecolorallocate($image, 0,0,0);  
  19.         // 設(shè)定文字顏色數(shù)組   
  20.         $colorList[] = ImageColorAllocate($image, 15,73,210);  
  21.         $colorList[] = ImageColorAllocate($image, 0,64,0);  
  22.         $colorList[] = ImageColorAllocate($image, 0,0,64);  
  23.         $colorList[] = ImageColorAllocate($image, 0,128,128);  
  24.         $colorList[] = ImageColorAllocate($image, 27,52,47);  
  25.         $colorList[] = ImageColorAllocate($image, 51,0,102);  
  26.         $colorList[] = ImageColorAllocate($image, 0,0,145);  
  27.         $colorList[] = ImageColorAllocate($image, 0,0,113);  
  28.         $colorList[] = ImageColorAllocate($image, 0,51,51);  
  29.         $colorList[] = ImageColorAllocate($image, 158,180,35);  
  30.         $colorList[] = ImageColorAllocate($image, 59,59,59);  
  31.         $colorList[] = ImageColorAllocate($image, 0,0,0);  
  32.         $colorList[] = ImageColorAllocate($image, 1,128,180);  
  33.         $colorList[] = ImageColorAllocate($image, 0,153,51);  
  34.         $colorList[] = ImageColorAllocate($image, 60,131,1);  
  35.         $colorList[] = ImageColorAllocate($image, 0,0,0);  
  36.         $fontcolor = ImageColorAllocate($image, 0,0,0);  
  37.         $gray = ImageColorAllocate($image, 245,245,245);   
  38.           
  39.         $color = imagecolorallocate($image, 255,255,255);  
  40.         $color2 = imagecolorallocate($image, 255,0,0);  
  41.           
  42.         imagefill($image, 0, 0, $gray);  
  43.           
  44.         $space = 15;        // 字符間距  
  45.         if($i > 0)          // 屏蔽***幀  
  46.         {  
  47.             for ($k = 0; $k < strlen($authstr); $k++)   
  48.             {   
  49.                 $colorRandom = mt_rand(0,sizeof($colorList)-1);   
  50.                 $float_top = rand(0,4);  
  51.                 $float_left = rand(0,3);  
  52.                 imagestring($image, 6, $space * $k$top + $float_topsubstr($authstr$k, 1), $colorList[$colorRandom]);  
  53.             }  
  54.         }  
  55.           
  56.         for ($k = 0; $k < 20; $k++)   
  57.         {   
  58.             $colorRandom = mt_rand(0,sizeof($colorList)-1);   
  59.             imagesetpixel($image, rand()%70 , rand()%15 , $colorList[$colorRandom]);   
  60.       
  61.         }  
  62.         // 添加干擾線  
  63.         for($k = 0; $k < 3; $k++)  
  64.         {  
  65.             $colorRandom = mt_rand(0, sizeof($colorList)-1);   
  66.             // $todrawline = rand(0,1);  
  67.             $todrawline = 1;  
  68.             if($todrawline)  
  69.             {  
  70.                 imageline($image, mt_rand(0, $board_width), mt_rand(0,$board_height), mt_rand(0,$board_width), mt_rand(0,$board_height), $colorList[$colorRandom]);  
  71.             }  
  72.             else   
  73.             {  
  74.                 $w = mt_rand(0,$board_width);  
  75.                 $h = mt_rand(0,$board_width);  
  76.                 imagearc($image$board_width - floor($w / 2) , floor($h / 2), $w$h,  rand(90,180), rand(180,270), $colorList[$colorRandom]);  
  77.             }  
  78.         }  
  79.         imagegif($image);  
  80.         imagedestroy($image);  
  81.         $imagedata[] = ob_get_contents();  
  82.         ob_clean();    
  83.         ++$i;    
  84.     }  
  85.       
  86.     $gif = new GIFEncoder($imagedata);    
  87.     Header ('Content-type:image/gif');    
  88.     echo $gif->GetAnimation();    

有關(guān)GIFEncoder類,請下載本文附件:animation.ra

附件下載:animation.rar 2.96KB

原文鏈接:http://www.phper.org.cn/?post=116

責(zé)任編輯:張偉 來源: ITEYE
相關(guān)推薦

2009-11-23 16:34:22

PHP GD庫

2024-01-29 08:32:10

Python驗(yàn)證碼識(shí)別

2015-09-21 15:31:05

php實(shí)現(xiàn)驗(yàn)證碼

2009-12-11 15:17:52

PHP驗(yàn)證碼調(diào)用

2009-11-26 10:48:59

PHP驗(yàn)證碼

2009-11-23 16:59:23

PHP圖形驗(yàn)證碼

2009-08-06 16:30:58

C#代碼和驗(yàn)證碼圖片

2023-10-27 08:53:13

Python驗(yàn)證碼圖片識(shí)別

2019-08-23 09:52:59

Axure 產(chǎn)品經(jīng)理

2013-06-19 10:19:59

2021-08-11 09:51:24

人工智能機(jī)器學(xué)習(xí)技術(shù)

2015-03-18 10:41:34

圖片驗(yàn)證驗(yàn)證碼12306

2009-12-08 11:16:07

PHP動(dòng)態(tài)圖像創(chuàng)建

2015-03-23 17:58:04

驗(yàn)證碼倒計(jì)時(shí)并行

2021-01-19 10:29:34

短信驗(yàn)證碼密碼

2022-02-11 07:10:15

驗(yàn)證碼

2017-12-21 07:38:19

2009-02-09 14:17:36

2009-08-11 14:05:28

JSP驗(yàn)證碼
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)