Changeset 913


Ignore:
Timestamp:
May 7, 2015 12:28:04 PM (10 years ago)
Author:
dungnv
Message:
 
Location:
pro-violet-viettel/www/deploy/api/platform
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/www/deploy/api/platform/lib/violetUtil.class.php

    r902 r913  
    3838    }
    3939  }
     40
    4041   public function createThumb($pathToImage="") {
    4142
    4243        if (is_file($pathToImage)) {
    43      
    4444            $info = pathinfo($pathToImage);
    4545            $extension = strtolower($info['extension']);
    46            
     46                        error_log(date('YmdHis') .' - '.$pathToImage .' - '. $extension . "\n", 3, '/srv/www/sbg/log/thumbcreator.log');
     47            $imagefunc = 'imagejpeg';
     48
    4749            if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) {
    4850
    4951                switch ($extension) {
    50                     case 'jpg':
    51                         $img = imagecreatefromjpeg("{$pathToImage}");
    52                         break;
    53                     case 'jpeg':
    54                         $img = imagecreatefromjpeg("{$pathToImage}");
    55                         break;
    5652                    case 'png':
    5753                        $img = imagecreatefrompng("{$pathToImage}");
     54                        $imagefunc = 'imagepng';
    5855                        break;
    5956                    case 'gif':
    6057                        $img = imagecreatefromgif("{$pathToImage}");
     58                        $imagefunc = 'imagegif';
    6159                        break;
     60                    case 'jpg':
     61                    case 'jpeg':
    6262                    default:
    6363                        $img = imagecreatefromjpeg("{$pathToImage}");
     64                        $imagefunc = 'imagejpeg';
     65                        break;
    6466                }
     67
    6568                list($width, $height) = getimagesize($pathToImage);
    66                 $new_width = 64;
    67                 $new_height = 50;
     69
     70                $max_width = 64;
     71                $max_height = 50;
     72                $ratio = $max_width/$max_height;
     73                $cropped_width = $height/$ratio;
     74                $cropped_height = $width/$ratio;
     75
     76                if ($width < $height) {
     77                        $new_height = $max_height;
     78                        $new_width = $width * ($max_height/$height);
     79                }
     80                else if ($width > $height) {
     81                        $new_width = $max_width;
     82                        $new_height = $height * ($max_width/$width);
     83                }
     84
    6885                $image_p = imagecreatetruecolor($new_width, $new_height);
    69          
     86
    7087                imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    71                 $thumnail = $info['dirname']."/".$info['filename']."_thumb.jpg";
    72                 imagejpeg($image_p,$thumnail, 30);
     88
     89                $thumnail = $info['dirname'].DIRECTORY_SEPARATOR.$info['filename'].'_thumb.'.$extension;
     90
     91                if ($imagefunc == 'imagegif' || $imagefunc == 'imagepng' ) {
     92                        call_user_func($imagefunc, $image_p, $thumnail);
     93                }
     94                else {
     95                        call_user_func($imagefunc, $image_p, $thumnail, 30);
     96                }
     97
    7398                return str_replace($_SERVER['DOCUMENT_ROOT'], "", $thumnail);
    7499            } else {
     
    78103            return "";
    79104        }
    80        
     105
    81106        return sfView::NONE;
    82107    }
  • pro-violet-viettel/www/deploy/api/platform/modules/space/actions/actions.class.php

    r905 r913  
    1717    public function executeIndex() {
    1818        $this->forward('default', 'module');
    19     }
    20 
    21     private function createImateThumbnail($fileName, &$thumnail = '') {
    22         $thumnailPath = dirname($fileName);
    23         $rawFileName = str_replace($thumnailPath, '', $fileName);
    24         $thumbnailfileName = substr($rawFileName, 0, strlen($rawFileName) - 4) . '_thumb.jpg';
    25         list($width, $height) = getimagesize($fileName);
    26         $new_width = 64;
    27         $new_height = 50;
    28         $image_p = imagecreatetruecolor($new_width, $new_height);
    29         $image = imagecreatefromjpeg($fileName);
    30         imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    31         $thumnail = $thumnailPath . $thumbnailfileName;
    32         return imagejpeg($image_p, $thumnailPath . $thumbnailfileName, 30);
    3319    }
    3420
     
    159145        $tblfile->setFileType($currentFile->getFileType());
    160146        $tblfile->setFileDate(date('Y-m-d H:i:s'));
    161         $tblfile->save(); 
     147        $tblfile->save();
    162148
    163149        $c = new Criteria();
     
    483469        }
    484470
    485        
    486 
    487471        if ($response == 1) {
    488472            $aryError = array('err' => "", 'errCode' => 0);
    489473            $ext = pathinfo($fileUrl, PATHINFO_EXTENSION);
    490474            $thumbnail = "";
    491             if (in_array($ext, array("jpg", "jpeg", "png", "gif", "tiff", "dvg", "bmp"))) {
     475            if (in_array(strtolower($ext), array("jpg", "jpeg", "png", "gif", "tiff", "dvg", "bmp"))) {
    492476            $thumbnail=violetUtil::createThumb($filePath);
    493477            }
  • pro-violet-viettel/www/deploy/api/platform/modules/space/templates/dirSuccess.php

    r903 r913  
    3737          $filePath = $tblres->getFullFilename();
    3838          $filePath = str_replace($_SERVER['DOCUMENT_ROOT'], '', $filePath);
    39           $thumbnail = str_replace($name, "", $fileName). $names[0]."_thumb.jpg";
     39          $thumbnail = str_replace($name, "", $fileName). $names[0].'_thumb.'.$ext;
    4040      }
    4141      else
     
    4646        }
    4747      }
    48      
     48
    4949      $fileSize = $tblres->getResFilesize();
    5050      ?>
Note: See TracChangeset for help on using the changeset viewer.