Changeset 5492
- Timestamp:
- 10/13/07 09:33:28 (6 years ago)
- Files:
-
- plugins/sfThumbnailPlugin/README (modified) (1 diff)
- plugins/sfThumbnailPlugin/lib/sfImageMagickAdapter.class.php (modified) (4 diffs)
- plugins/sfThumbnailPlugin/lib/sfThumbnail.class.php (modified) (5 diffs)
- plugins/sfThumbnailPlugin/package.xml (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfThumbnailPlugin/README
r5051 r5492 127 127 }}} 128 128 129 By default sfThumbnail resizes the image in order to get to the desired width and height of the thumbnail. But what if you want to force the thumbnail to be a certain width and height but without distorting the image of the source size scale is different than the thumbnail size scale 130 Now you can use a custom option "method" to achieve just that but "shaving" the source image in order to get it to be the same scale as the thumbnail and them resize it to the required dimentions. 131 When "shave_bottom" is used and the image’s width is greater than the height then sfThumbnail shaves from both left side and right side until the desired scale. 132 There is one requirement for the "method" option to work as expected and it is to turn off scaling (set the third parameter of sfThumbnail to FALSE) 133 134 {{{ 135 $thumbnail = new sfThumbnail(150, 150, false, true, 75, 'sfImageMagickAdapter', array('method' => 'shave_all')); 136 137 $thumbnail->loadFile('http://www.walkerbooks.co.uk/assets_walker/dynamic/1172005677146.png'); 138 $thumbnail->save('/tmp/shave.png', 'image/png'); 139 }}} 140 129 141 == Changelog == 130 142 131 143 === Trunk === 132 144 133 === 2007-12-09 | 1.4.0 Stable === 145 === 2007-09-15 | 1.5.0 Stable === 146 147 * kupokomapa: toString($mime) method now works for both adapters 148 * kupokomapa: loadFile() method can now accept a URI if sfWebBrowserPluging is available 149 * kupokomapa: Implemented "method" option for sfImageMagickAdapter where "method" for now can be "shave_all" or "shave_bottom" 150 151 === 2007-09-12 | 1.4.0 Stable === 134 152 135 153 * davedash: Added toString($mime) function to save file to a string plugins/sfThumbnailPlugin/lib/sfImageMagickAdapter.class.php
r3975 r5492 4 4 * This file is part of the symfony package. 5 5 * (c) 2004-2007 Fabien Potencier <fabien.potencier@symfony-project.com> 6 * 6 * 7 7 * For the full copyright and license information, please view the LICENSE 8 8 * file that was distributed with this source code. … … 162 162 } 163 163 164 public function toString($thumbnail, $targetMime = null) 165 { 166 ob_start(); 167 $this->save($thumbnail, null, $targetMime); 168 169 return ob_get_clean(); 170 } 171 164 172 public function loadFile($thumbnail, $image) 165 173 { … … 211 219 public function save($thumbnail, $thumbDest, $targetMime = null) 212 220 { 213 $command = ' -thumbnail '; 221 $command = ''; 222 223 $width = $this->sourceWidth; 224 $height = $this->sourceHeight; 225 $x = $y = 0; 226 switch (@$this->options['method']) { 227 case "shave_all": 228 if ($width > $height) 229 { 230 $x = ceil(($width - $height) / 2 ); 231 $width = $height; 232 } 233 elseif ($height > $width) 234 { 235 $y = ceil(($height - $width) / 2); 236 $height = $width; 237 } 238 239 $command = sprintf(" -shave %dx%d", $x, $y); 240 break; 241 case "shave_bottom": 242 if ($width > $height) 243 { 244 $x = ceil(($width - $height) / 2 ); 245 $width = $height; 246 } 247 elseif ($height > $width) 248 { 249 $y = 0; 250 $height = $width; 251 } 252 253 if (is_null($thumbDest)) 254 { 255 $command = sprintf( 256 " -crop %dx%d+%d+%d %s '-' | %s", 257 $width, $height, 258 $x, $y, 259 escapeshellarg($this->image), 260 $this->magickCommands['convert'] 261 ); 262 263 $this->image = '-'; 264 } 265 else 266 { 267 $command = sprintf( 268 " -crop %dx%d+%d+%d %s %s && %s", 269 $width, $height, 270 $x, $y, 271 escapeshellarg($this->image), escapeshellarg($thumbDest), 272 $this->magickCommands['convert'] 273 ); 274 275 $this->image = $thumbDest; 276 } 277 278 break; 279 } // end switch 280 281 $command .= ' -thumbnail '; 214 282 $command .= $thumbnail->getThumbWidth().'x'.$thumbnail->getThumbHeight(); 215 283 … … 236 304 } 237 305 238 exec($this->magickCommands['convert'].' '.$command.' '.escapeshellarg($this->image).$extract.' '.escapeshellarg($thumbDest)); 306 $output = (is_null($thumbDest))?'-':$thumbDest; 307 $output = (($mime = array_search($targetMime, $this->mimeMap))?$mime.':':'').$output; 308 309 $cmd = $this->magickCommands['convert'].' '.$command.' '.escapeshellarg($this->image).$extract.' '.escapeshellarg($output); 310 311 (is_null($thumbDest))?passthru($cmd):exec($cmd); 239 312 } 240 313 plugins/sfThumbnailPlugin/lib/sfThumbnail.class.php
r4552 r5492 4 4 * This file is part of the symfony package. 5 5 * (c) 2004-2007 Fabien Potencier <fabien.potencier@symfony-project.com> 6 * 6 * 7 7 * For the full copyright and license information, please view the LICENSE 8 8 * file that was distributed with this source code. … … 12 12 * sfThumbnail provides a mechanism for creating thumbnail images. 13 13 * 14 * This is taken from Harry Fueck's Thumbnail class and 14 * This is taken from Harry Fueck's Thumbnail class and 15 15 * converted for PHP5 strict compliance for use with symfony. 16 16 * … … 32 32 33 33 /** 34 * Temporary file if the source is not local 35 */ 36 protected $tempFile = null; 37 38 /** 34 39 * Thumbnail constructor 35 40 * … … 67 72 public function loadFile($image) 68 73 { 74 if (eregi('http(s)?://', $image)) 75 { 76 if (class_exists('sfWebBrowser')) 77 { 78 if (!is_null($this->tempFile)) { 79 unlink($this->tempFile); 80 } 81 $this->tempFile = tempnam('/tmp', 'sfThumbnailPlugin'); 82 83 $b = new sfWebBrowser(); 84 try 85 { 86 $b->get($image); 87 if ($b->getResponseCode() != 200) { 88 throw new Exception(sprintf('%s returned error code %s', $image, $b->getResponseCode())); 89 } 90 file_put_contents($this->tempFile, $b->getResponseText()); 91 if (!filesize($this->tempFile)) { 92 throw new Exception('downloaded file is empty'); 93 } else { 94 $image = $this->tempFile; 95 } 96 } 97 catch (Exception $e) 98 { 99 throw new Exception("Source image is a URL but it cannot be used because ". $e->getMessage()); 100 } 101 } 102 else 103 { 104 throw new Exception("Source image is a URL but sfWebBrowserPlugin is not installed"); 105 } 106 } 107 69 108 $this->adapter->loadFile($this, $image); 70 109 } … … 104 143 * If no target mime type is specified, the thumbnail is created with the same mime type as the source file. 105 144 * 106 * This works only for the GD Adapter 107 * 108 * @param string The mime-type of the thumbnail (possible values are 'image/jpeg', 'image/png', and 'image/gif') 145 * 146 * @param string The mime-type of the thumbnail (possible values are adapter dependent) 109 147 * 110 148 * @access public 111 149 * @return string 112 150 */ 113 public function toString($t humbDest, $targetMime = null)151 public function toString($targetMime = null) 114 152 { 115 153 return $this->adapter->toString($this, $targetMime); 116 154 } 117 155 118 119 156 public function freeSource() 120 157 { 158 if (!is_null($this->tempFile)) { 159 unlink($this->tempFile); 160 } 121 161 $this->adapter->freeSource(); 122 162 } plugins/sfThumbnailPlugin/package.xml
r5051 r5492 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 <package packagerversion="1. 4.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">2 <package packagerversion="1.6.1" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> 3 3 <name>sfThumbnailPlugin</name> 4 4 <channel>pear.symfony-project.com</channel> … … 11 11 <active>yes</active> 12 12 </lead> 13 <date>2007-09-12</date> 13 <date>2007-09-15</date> 14 <time>13:11:08</time> 14 15 <version> 15 <release>1.4.0</release>16 <api>1.0.0</api>16 <release>1.5.0</release> 17 <api>1.0.0</api> 17 18 </version> 18 19 <stability> … … 24 25 <contents> 25 26 <dir name="/"> 26 <file role="data" name="README" /> 27 <file role="data" name="LICENSE" /> 28 29 <dir name="lib"> 30 <file role="data" name="sfThumbnail.class.php" /> 31 <file role="data" name="sfGDAdapter.class.php" /> 32 <file role="data" name="sfImageMagickAdapter.class.php" /> 33 </dir> 27 <file md5sum="ade44239bce430f61f7c0c8cd1ce89b0" name="lib/sfThumbnail.class.php" role="data" /> 28 <file md5sum="ea7aec8b4be6212af8434f65efa85a69" name="lib/sfGDAdapter.class.php" role="data" /> 29 <file md5sum="add9e55ed76cc8d607b11bf2a4704aea" name="lib/sfImageMagickAdapter.class.php" role="data" /> 30 <file md5sum="c5de5dccc5785beae22f92424d51cad6" name="README" role="data" /> 31 <file md5sum="c0ab88a4687e9ff8e0fb6c95ca49ed74" name="LICENSE" role="data" /> 34 32 </dir> 35 33 </contents> 36 37 34 <dependencies> 38 35 <required> … … 52 49 </required> 53 50 </dependencies> 54 55 <phprelease> 56 </phprelease> 57 58 <changelog> 59 </changelog> 51 <phprelease /> 52 <changelog /> 60 53 </package>