Index: /pro-violet-viettel/www/deploy/api/platform/lib/violetUtil.class.php
===================================================================
--- /pro-violet-viettel/www/deploy/api/platform/lib/violetUtil.class.php	(revision 912)
+++ /pro-violet-viettel/www/deploy/api/platform/lib/violetUtil.class.php	(revision 913)
@@ -38,37 +38,62 @@
     }
   }
+
    public function createThumb($pathToImage="") {
 
         if (is_file($pathToImage)) {
-      
             $info = pathinfo($pathToImage);
             $extension = strtolower($info['extension']);
-            
+			error_log(date('YmdHis') .' - '.$pathToImage .' - '. $extension . "\n", 3, '/srv/www/sbg/log/thumbcreator.log');
+            $imagefunc = 'imagejpeg';
+
             if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) {
 
                 switch ($extension) {
-                    case 'jpg':
-                        $img = imagecreatefromjpeg("{$pathToImage}");
-                        break;
-                    case 'jpeg':
-                        $img = imagecreatefromjpeg("{$pathToImage}");
-                        break;
                     case 'png':
                         $img = imagecreatefrompng("{$pathToImage}");
+                        $imagefunc = 'imagepng';
                         break;
                     case 'gif':
                         $img = imagecreatefromgif("{$pathToImage}");
+                        $imagefunc = 'imagegif';
                         break;
+                    case 'jpg':
+                    case 'jpeg':
                     default:
                         $img = imagecreatefromjpeg("{$pathToImage}");
+                        $imagefunc = 'imagejpeg';
+                        break;
                 }
+
                 list($width, $height) = getimagesize($pathToImage);
-                $new_width = 64;
-                $new_height = 50;
+
+                $max_width = 64;
+                $max_height = 50;
+                $ratio = $max_width/$max_height;
+                $cropped_width = $height/$ratio;
+                $cropped_height = $width/$ratio;
+
+                if ($width < $height) {
+                	$new_height = $max_height;
+                	$new_width = $width * ($max_height/$height);
+                }
+                else if ($width > $height) {
+                	$new_width = $max_width;
+                	$new_height = $height * ($max_width/$width);
+                }
+
                 $image_p = imagecreatetruecolor($new_width, $new_height);
-          
+
                 imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
-                $thumnail = $info['dirname']."/".$info['filename']."_thumb.jpg";
-                imagejpeg($image_p,$thumnail, 30);
+
+                $thumnail = $info['dirname'].DIRECTORY_SEPARATOR.$info['filename'].'_thumb.'.$extension;
+
+                if ($imagefunc == 'imagegif' || $imagefunc == 'imagepng' ) {
+                	call_user_func($imagefunc, $image_p, $thumnail);
+                }
+                else {
+                	call_user_func($imagefunc, $image_p, $thumnail, 30);
+                }
+
                 return str_replace($_SERVER['DOCUMENT_ROOT'], "", $thumnail);
             } else {
@@ -78,5 +103,5 @@
             return "";
         }
-       
+
         return sfView::NONE;
     }
Index: /pro-violet-viettel/www/deploy/api/platform/modules/space/actions/actions.class.php
===================================================================
--- /pro-violet-viettel/www/deploy/api/platform/modules/space/actions/actions.class.php	(revision 912)
+++ /pro-violet-viettel/www/deploy/api/platform/modules/space/actions/actions.class.php	(revision 913)
@@ -17,18 +17,4 @@
     public function executeIndex() {
         $this->forward('default', 'module');
-    }
-
-    private function createImateThumbnail($fileName, &$thumnail = '') {
-        $thumnailPath = dirname($fileName);
-        $rawFileName = str_replace($thumnailPath, '', $fileName);
-        $thumbnailfileName = substr($rawFileName, 0, strlen($rawFileName) - 4) . '_thumb.jpg';
-        list($width, $height) = getimagesize($fileName);
-        $new_width = 64;
-        $new_height = 50;
-        $image_p = imagecreatetruecolor($new_width, $new_height);
-        $image = imagecreatefromjpeg($fileName);
-        imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
-        $thumnail = $thumnailPath . $thumbnailfileName;
-        return imagejpeg($image_p, $thumnailPath . $thumbnailfileName, 30);
     }
 
@@ -159,5 +145,5 @@
         $tblfile->setFileType($currentFile->getFileType());
         $tblfile->setFileDate(date('Y-m-d H:i:s'));
-        $tblfile->save(); 
+        $tblfile->save();
 
         $c = new Criteria();
@@ -483,11 +469,9 @@
         }
 
-       
-
         if ($response == 1) {
             $aryError = array('err' => "", 'errCode' => 0);
             $ext = pathinfo($fileUrl, PATHINFO_EXTENSION);
             $thumbnail = "";
-            if (in_array($ext, array("jpg", "jpeg", "png", "gif", "tiff", "dvg", "bmp"))) {
+            if (in_array(strtolower($ext), array("jpg", "jpeg", "png", "gif", "tiff", "dvg", "bmp"))) {
             $thumbnail=violetUtil::createThumb($filePath);
             }
Index: /pro-violet-viettel/www/deploy/api/platform/modules/space/templates/dirSuccess.php
===================================================================
--- /pro-violet-viettel/www/deploy/api/platform/modules/space/templates/dirSuccess.php	(revision 912)
+++ /pro-violet-viettel/www/deploy/api/platform/modules/space/templates/dirSuccess.php	(revision 913)
@@ -37,5 +37,5 @@
           $filePath = $tblres->getFullFilename();
           $filePath = str_replace($_SERVER['DOCUMENT_ROOT'], '', $filePath);
-          $thumbnail = str_replace($name, "", $fileName). $names[0]."_thumb.jpg";
+          $thumbnail = str_replace($name, "", $fileName). $names[0].'_thumb.'.$ext;
       }
       else
@@ -46,5 +46,5 @@
         }
       }
-      
+
       $fileSize = $tblres->getResFilesize();
       ?>
