4-1验证码类封装之GD库验证

 1 <?php
 2 /**
 3  * GDBasic.php
 4  
 5  * description GD基础类
 6  */
 7 
 8 namespace ImoocLib;
 9 
10 
11 class GDBasic
12 {
13     protected static $_check =false;
14 
15     //检查服务器环境中gd库
16     public static function check()
17     {
18         //当静态变量不为false
19         if(static::$_check)
20         {
21             return true;
22         }
23 
24         //检查gd库是否加载
25         if(!function_exists("gd_info"))
26         {
27             throw new Exception('GD is not exists');
28         }
29 
30         //检查gd库版本
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 }
原文地址:https://www.cnblogs.com/kay-learning/p/8973195.html