Development

Changeset 5492

You must first sign up to be able to contribute.

Changeset 5492

Show
Ignore:
Timestamp:
10/13/07 09:33:28 (6 years ago)
Author:
kupokomapa
Message:

* kupokomapa: toString($mime) method now works for both adapters
* kupokomapa: loadFile() method can now accept a URI if sfWebBrowserPluging is available
* kupokomapa: Implemented "method" option for sfImageMagickAdapter where "method" for now can be "shave_all" or "shave_bottom"

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfThumbnailPlugin/README

    r5051 r5492  
    127127}}} 
    128128 
     129By 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 
     130Now 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. 
     131When "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. 
     132There 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 
    129141== Changelog == 
    130142 
    131143=== Trunk === 
    132144 
    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 === 
    134152 
    135153 * davedash: Added toString($mime) function to save file to a string 
  • plugins/sfThumbnailPlugin/lib/sfImageMagickAdapter.class.php

    r3975 r5492  
    44 * This file is part of the symfony package. 
    55 * (c) 2004-2007 Fabien Potencier <fabien.potencier@symfony-project.com> 
    6  *  
     6 * 
    77 * For the full copyright and license information, please view the LICENSE 
    88 * file that was distributed with this source code. 
     
    162162  } 
    163163 
     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 
    164172  public function loadFile($thumbnail, $image) 
    165173  { 
     
    211219  public function save($thumbnail, $thumbDest, $targetMime = null) 
    212220  { 
    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 '; 
    214282    $command .= $thumbnail->getThumbWidth().'x'.$thumbnail->getThumbHeight(); 
    215283 
     
    236304    } 
    237305 
    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); 
    239312  } 
    240313 
  • plugins/sfThumbnailPlugin/lib/sfThumbnail.class.php

    r4552 r5492  
    44 * This file is part of the symfony package. 
    55 * (c) 2004-2007 Fabien Potencier <fabien.potencier@symfony-project.com> 
    6  *  
     6 * 
    77 * For the full copyright and license information, please view the LICENSE 
    88 * file that was distributed with this source code. 
     
    1212 * sfThumbnail provides a mechanism for creating thumbnail images. 
    1313 * 
    14  * This is taken from Harry Fueck's Thumbnail class and  
     14 * This is taken from Harry Fueck's Thumbnail class and 
    1515 * converted for PHP5 strict compliance for use with symfony. 
    1616 * 
     
    3232 
    3333  /** 
     34   * Temporary file if the source is not local 
     35   */ 
     36  protected $tempFile = null; 
     37 
     38  /** 
    3439   * Thumbnail constructor 
    3540   * 
     
    6772  public function loadFile($image) 
    6873  { 
     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 
    69108    $this->adapter->loadFile($this, $image); 
    70109  } 
     
    104143   * If no target mime type is specified, the thumbnail is created with the same mime type as the source file. 
    105144   * 
    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) 
    109147   * 
    110148   * @access public 
    111149   * @return string 
    112150   */ 
    113   public function toString($thumbDest, $targetMime = null) 
     151  public function toString($targetMime = null) 
    114152  { 
    115153    return $this->adapter->toString($this, $targetMime); 
    116154  } 
    117155 
    118  
    119156  public function freeSource() 
    120157  { 
     158    if (!is_null($this->tempFile)) { 
     159      unlink($this->tempFile); 
     160    } 
    121161    $this->adapter->freeSource(); 
    122162  } 
  • plugins/sfThumbnailPlugin/package.xml

    r5051 r5492  
    11<?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"> 
    33 <name>sfThumbnailPlugin</name> 
    44 <channel>pear.symfony-project.com</channel> 
     
    1111  <active>yes</active> 
    1212 </lead> 
    13  <date>2007-09-12</date> 
     13 <date>2007-09-15</date> 
     14 <time>13:11:08</time> 
    1415 <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> 
    1718 </version> 
    1819 <stability> 
     
    2425 <contents> 
    2526  <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" /> 
    3432  </dir> 
    3533 </contents> 
    36  
    3734 <dependencies> 
    3835  <required> 
     
    5249  </required> 
    5350 </dependencies> 
    54  
    55  <phprelease> 
    56  </phprelease> 
    57  
    58  <changelog> 
    59  </changelog> 
     51 <phprelease /> 
     52 <changelog /> 
    6053</package>