예제 #1
0
 /**
  * Apply the transformation to the image and returns the resized image
  */
 protected function transform(sfImage $image)
 {
     list($target_w, $target_h) = $this->computeTargetSize($image->getWidth(), $image->getHeight());
     return $image->resizeSimple($target_w, $target_h);
 }
예제 #2
0
 /**
  * Apply the transformation to the image and returns the resized image
  */
 protected function transform(sfImage $image)
 {
     $source_w = $image->getWidth();
     $source_h = $image->getHeight();
     $target_w = $this->width;
     $target_h = $this->height;
     if (is_numeric($this->width) && $this->width > 0 && $source_w > 0) {
         if (!$this->inflate && $target_w > $source_w) {
             $target_w = $source_w;
         }
         if ($this->proportional) {
             // Compute the new height in order to keep the aspect ratio
             // and clamp it to the maximum height
             $target_h = round($source_h / $source_w * $target_w);
             if (is_numeric($this->height) && $this->height < $target_h && $source_h > 0) {
                 $target_h = $this->height;
                 $target_w = round($source_w / $source_h * $target_h);
             }
         }
     }
     if (is_numeric($this->height) && $this->height > 0 && $source_h > 0) {
         if (!$this->inflate && $target_h > $source_h) {
             $target_h = $source_h;
         }
         if ($this->proportional) {
             // Compute the new width in order to keep the aspect ratio
             // and clamp it to the maximum width
             $target_w = round($source_w / $source_h * $target_h);
             if (is_numeric($this->width) && $this->width < $target_w && $source_w > 0) {
                 $target_w = $this->width;
                 $target_h = round($source_h / $source_w * $target_w);
             }
         }
     }
     return $image->resizeSimple($target_w, $target_h);
 }