4-1 GD library verification of verification code package

1 <? php
 2  /* *
 3  * GDBasic.php
 4   
5  * description GD base class
 6   */ 
7  
8  namespace Imooc\Lib;
 9  
10  
11  class GDBasic
 12  {
 13      protected  static  $_check = false ;
 14  
15      // check gd library in the server environment 
16      public  static  function check()
 17      {
 18          // When the static variable is not false 
19          if ( static:: $_check )
 20          {
 21              return  true ;
 22          }
 23  
24          // Check if gd library is loaded 
25          if (! function_exists ("gd_info" ))
 26          {
 27              throw  new \ Exception ('GD is not exists' );
 28          }
 29  
30          // Check gd library version 
31          $version = '' ;
 32          $info = gd_info();
 33          if ( preg_match("/\\d+\\.\\d+(?:\\.\\d+)?/", $info["GD Version"], $matches))
34         {
35             $version = $matches[0];
36         }
37 
38         //当gd库版本小于2.0.1
39         if(!version_compare($version,'2.0.1','>='))
40         {
41             throw new \Exception("GD requires GD version '2.0.1' or greater, you have " . $version);
42         }
43 
44         self::$_check = true;
45         return self::$_check;
46     }
47 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325113292&siteId=291194637