- Timestamp:
- May 7, 2015 12:28:04 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pro-violet-viettel/www/deploy/api/platform/lib/violetUtil.class.php
r902 r913 38 38 } 39 39 } 40 40 41 public function createThumb($pathToImage="") { 41 42 42 43 if (is_file($pathToImage)) { 43 44 44 $info = pathinfo($pathToImage); 45 45 $extension = strtolower($info['extension']); 46 46 error_log(date('YmdHis') .' - '.$pathToImage .' - '. $extension . "\n", 3, '/srv/www/sbg/log/thumbcreator.log'); 47 $imagefunc = 'imagejpeg'; 48 47 49 if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) { 48 50 49 51 switch ($extension) { 50 case 'jpg':51 $img = imagecreatefromjpeg("{$pathToImage}");52 break;53 case 'jpeg':54 $img = imagecreatefromjpeg("{$pathToImage}");55 break;56 52 case 'png': 57 53 $img = imagecreatefrompng("{$pathToImage}"); 54 $imagefunc = 'imagepng'; 58 55 break; 59 56 case 'gif': 60 57 $img = imagecreatefromgif("{$pathToImage}"); 58 $imagefunc = 'imagegif'; 61 59 break; 60 case 'jpg': 61 case 'jpeg': 62 62 default: 63 63 $img = imagecreatefromjpeg("{$pathToImage}"); 64 $imagefunc = 'imagejpeg'; 65 break; 64 66 } 67 65 68 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 68 85 $image_p = imagecreatetruecolor($new_width, $new_height); 69 86 70 87 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 73 98 return str_replace($_SERVER['DOCUMENT_ROOT'], "", $thumnail); 74 99 } else { … … 78 103 return ""; 79 104 } 80 105 81 106 return sfView::NONE; 82 107 }
Note: See TracChangeset
for help on using the changeset viewer.