Development

Changeset 1706

You must first sign up to be able to contribute.

Changeset 1706

Show
Ignore:
Timestamp:
08/21/06 13:57:10 (8 years ago)
Author:
fabien
Message:

sfThumbnail plugin correct a bug and enhancement (explicit width/height) (closes #677 - patch from sylvain)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfThumbnail/lib/sfThumbnail.class.php

    r1199 r1706  
    134134  /** 
    135135  * Thumbnail constructor 
    136   * @param int max width of thumbnail 
    137   * @param int max height of thumbnail 
     136  * @param int (optional) max width of thumbnail 
     137  * @param int (optional) max height of thumbnail 
    138138  * @param boolean (optional) if true image scales 
    139139  * @param boolean (optional) if true inflate small images 
    140140  * @access public 
    141141  */ 
    142   public function __construct($maxWidth, $maxHeight, $scale = true, $inflate = true) 
     142  public function __construct($maxWidth = null, $maxHeight = null, $scale = true, $inflate = true) 
    143143  { 
    144144    $this->maxWidth  = $maxWidth; 
     
    258258  private function initThumb() 
    259259  { 
     260    if ($this->maxWidth > 0) 
     261    { 
     262      $ratioWidth = $this->maxWidth / $this->sourceWidth; 
     263    } 
     264    if ($this->maxHeight > 0) 
     265    { 
     266      $ratioHeight = $this->maxHeight / $this->sourceHeight; 
     267    } 
     268 
    260269    if ($this->scale) 
    261270    { 
    262       if ($this->sourceWidth > $this->sourceHeight) 
    263       { 
    264         $this->thumbWidth=$this->maxWidth
    265         $this->thumbHeight=floor($this->sourceHeight*($this->maxWidth/$this->sourceWidth)); 
    266       } 
    267       else if ($this->sourceWidth < $this->sourceHeight) 
    268       { 
    269         $this->thumbHeight=$this->maxHeight; 
    270         $this->thumbWidth=floor($this->sourceWidth*($this->maxHeight/$this->sourceHeight)); 
    271       } 
    272       else 
    273       { 
    274         $this->thumbWidth=$this->maxWidth; 
    275         $this->thumbHeight=$this->maxHeight
    276       } 
     271      if ($this->maxWidth && $this->maxHeight) 
     272      { 
     273        $ratio = ($ratioWidth < $ratioHeight) ? $ratioWidth : $ratioHeight
     274      } 
     275      if ($this->maxWidth xor $this->maxHeight) 
     276      { 
     277        $ratio = (isset($ratioWidth)) ? $ratioWidth : $ratioHeight; 
     278      } 
     279      if ((!$this->maxWidth && !$this->maxHeight) || (!$this->inflate && $ratio > 1)) 
     280      { 
     281        $ratio = 1; 
     282      } 
     283 
     284      $this->thumbWidth = floor($ratio * $this->sourceWidth)
     285      $this->thumbHeight = floor($ratio * $this->sourceHeight); 
    277286    } 
    278287    else 
    279288    { 
    280       $this->thumbWidth=$this->maxWidth; 
    281       $this->thumbHeight=$this->maxHeight; 
     289      if (!$ratioWidth || (!$this->inflate && $ratioWidth > 1)) 
     290      { 
     291        $ratioWidth = 1; 
     292      } 
     293      if (!$ratioHeight || (!$this->inflate && $ratioHeight > 1)) 
     294      { 
     295        $ratioHeight = 1; 
     296      } 
     297      $this->thumbWidth = floor($ratioWidth * $this->sourceWidth); 
     298      $this->thumbHeight = floor($ratioHeight * $this->sourceHeight); 
    282299    } 
    283300 
    284301    $this->thumb = imagecreatetruecolor($this->thumbWidth, $this->thumbHeight); 
    285302 
    286     if ($this->sourceWidth <= $this->maxWidth && $this->sourceHeight <= $this->maxHeight && $this->inflate == false
     303    if ($this->sourceWidth == $this->maxWidth && $this->sourceHeight == $this->maxHeight
    287304    { 
    288305      $this->thumb= $this->source; 
  • plugins/sfThumbnail/package.xml

    r1199 r1706  
    1111  <active>yes</active> 
    1212 </lead> 
    13  <date>2006-04-13</date> 
     13 <date>2006-08-21</date> 
    1414 <version> 
    15    <release>1.0.2</release> 
     15   <release>1.0.3</release> 
    1616   <api>1.0.0</api> 
    1717 </version>