Changeset 19cc5b9 in github for program/include/rcube_image.php
- Timestamp:
- May 30, 2012 5:22:18 AM (12 months ago)
- Branches:
- master, HEAD, dev-browser-capabilities, pdo
- Children:
- d901205
- Parents:
- b9854b8
- File:
-
- 1 edited
-
program/include/rcube_image.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
program/include/rcube_image.php
r041c93c r19cc5b9 14 14 | | 15 15 | PURPOSE: | 16 | Image resizer |16 | Image resizer and converter | 17 17 | | 18 18 +-----------------------------------------------------------------------+ … … 25 25 { 26 26 private $image_file; 27 28 const TYPE_GIF = 1; 29 const TYPE_JPG = 2; 30 const TYPE_PNG = 3; 31 const TYPE_TIF = 4; 32 33 public static $extensions = array( 34 self::TYPE_GIF => 'gif', 35 self::TYPE_JPG => 'jpg', 36 self::TYPE_PNG => 'png', 37 self::TYPE_TIF => 'tif', 38 ); 39 27 40 28 41 function __construct($filename) … … 67 80 * @param string $filename Output filename 68 81 * 69 * @return Success of convert as true/false82 * @return bool True on success, False on failure 70 83 */ 71 84 public function resize($size, $filename = null) … … 96 109 97 110 if (in_array($type, explode(',', $p['types']))) { // Valid type? 98 $result = rcube::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace RGB -quality {quality} {-opts} {in} {type}:{out}', $p) === '';99 } 100 101 if ($result ) {111 $result = rcube::exec($convert . ' 2>&1 -flatten -auto-orient -colorspace RGB -quality {quality} {-opts} {in} {type}:{out}', $p); 112 } 113 114 if ($result === '') { 102 115 return true; 103 116 } … … 149 162 } 150 163 164 // @TODO: print error to the log? 165 return false; 166 } 167 168 /** 169 * Convert image to a given type 170 * 171 * @param int $type Destination file type (see class constants) 172 * @param string $filename Output filename (if empty, original file will be used 173 * and filename extension will be modified) 174 * 175 * @return bool True on success, False on failure 176 */ 177 public function convert($type, $filename = null) 178 { 179 $rcube = rcube::get_instance(); 180 $convert = $rcube->config->get('im_convert_path', false); 181 182 if (!$filename) { 183 $filename = $this->image_file; 184 185 // modify extension 186 if ($extension = self::$extensions[$type]) { 187 $filename = preg_replace('/\.[^.]+$/', '', $filename) . '.' . $extension; 188 } 189 } 190 191 // use ImageMagick 192 if ($convert) { 193 $p['in'] = $this->image_file; 194 $p['out'] = $filename; 195 $p['type'] = self::$extensions[$type]; 196 197 $result = rcube::exec($convert . ' 2>&1 -colorspace RGB -quality 75 {in} {type}:{out}', $p); 198 199 if ($result === '') { 200 return true; 201 } 202 } 203 204 // use GD extension (TIFF isn't supported) 205 $props = $this->props(); 206 $gd_types = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG); 207 208 if ($props['gd_type'] && in_array($props['gd_type'], $gd_types)) { 209 if ($props['gd_type'] == IMAGETYPE_JPEG) { 210 $image = imagecreatefromjpeg($this->image_file); 211 } 212 else if ($props['gd_type'] == IMAGETYPE_GIF) { 213 $image = imagecreatefromgif($this->image_file); 214 } 215 else if ($props['gd_type'] == IMAGETYPE_PNG) { 216 $image = imagecreatefrompng($this->image_file); 217 } 218 219 if ($type == self::TYPE_JPG) { 220 $result = imagejpeg($image, $filename, 75); 221 } 222 else if ($type == self::TYPE_GIF) { 223 $result = imagegif($image, $filename); 224 } 225 else if ($type == self::TYPE_PNG) { 226 $result = imagepng($image, $filename, 6, PNG_ALL_FILTERS); 227 } 228 } 151 229 152 230 // @TODO: print error to the log? … … 170 248 } 171 249 } 250 172 251 }
Note: See TracChangeset
for help on using the changeset viewer.
