Anonymous avatar Anonymous committed 80648de

add_static_get_extension_name_function

Comments (0)

Files changed (1)

gmagick_handler.php

  	 */
  	function make_thumb($img,$thumb_width = 0, $thumb_height = 0,$crop=false,$quality=90,$path = ''){
 
- 		 /* 检查缩略图宽度和高度是否合法 */
+        /* 检查缩略图宽度和高度是否合法 */
         if ($thumb_width == 0 && $thumb_height == 0)
         {
-        	 throw new Exception("width and height Invalid!");
+            throw new Exception("width and height Invalid!");
             return false;
         }
 
- 		/* 检查原始文件是否存在及获得原始文件的信息 */
+ 	/*检查原始文件是否存在及获得原始文件的信息 */
         $org_info = @getimagesize($img);
         if (!$org_info)
          {
-			 throw new Exception("image not exists");
+	    throw new Exception("image not exists");
             return false;
          }
 
- 		/* 创建当月目录 */
+ 	/* 创建当月目录 */
         if (empty($path))
         {
             $dir = 'images/' . date('Ym').'/';
             $dir = $path;
         }
 
-		 /* 如果目标目录不存在,则创建它 */
+        /* 如果目标目录不存在,则创建它 */
         if (!file_exists($dir))
          {
             if (!$this->make_dir($dir))
         /* 如果文件名为空,生成不重名随机文件名 */
         $filename = $this->unique_name($dir);
 
-        $filename .= '.jpg';
-
 		 try{	
 
 			$gmagick = new Gmagick($img);
+                        $ext = self::get_extension_name($gmagick->getimageformat());
+                        $filename .= '.'.$ext;
 
 			if($crop == false){
 
 				$canvas = new Gmagick();
-				$canvas->newimage($thumb_width,$thumb_height,$this->fillcolor,'jpeg');
+				$canvas->newimage($thumb_width,$thumb_height,$this->fillcolor,$gmagick->getimageformat());
 
 				$gmagick->scaleimage($thumb_width,$thumb_height,true);
 				/* 取得缩图的实际大小 */
 		}
 
  	}
+      
 
- 	 /**
-      *  生成指定目录不重名的文件名
-      *
-     * @access  public
-     * @param   string      $dir        要检查是否有同名文件的目录
-      *
-     * @return  string      文件名
-     */
+      static function get_extension_name($format){
+		
+	switch($format){
+		case 'JPEG':
+		     return 'jpg';
+		     break;
+                case 'PNG':
+                     return 'png';
+                     break;
+                case 'GIF':
+		     return 'GIF';
+                     break;
+                default:
+                     return 'jpg';
+		
+	}
+        	
+      }
+
+     /**
+       *  生成指定目录不重名的文件名
+       *
+       * @access  public
+       * @param   string      $dir        要检查是否有同名文件的目录
+       *
+       * @return  string      文件名
+       */
     private function unique_name($dir)
     {
         $filename = '';
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.