fit_width() static public method

Fits width and height by a passed width and keeps the ratio
static public fit_width ( integer $width, integer $height, integer $fit, boolean $force = false ) : array
$width integer
$height integer
$fit integer The new width
$force boolean If width and height are smaller than the box this will force upscaling
return array An array with a key and value for width and height
Esempio n. 1
0
 function fitWidth($width, $force = false)
 {
     $size = size::fit_width($this->width(), $this->height(), $width, $force);
     $this->info->width = $size['width'];
     $this->info->height = $size['height'];
     return $this;
 }
Esempio n. 2
0
 function size()
 {
     $maxWidth = $this->maxWidth;
     $maxHeight = $this->maxHeight;
     $upscale = $this->upscale;
     if ($this->crop == true) {
         if (!$maxWidth) {
             $maxWidth = $maxHeight;
         }
         if (!$maxHeight) {
             $maxHeight = $maxWidth;
         }
         $sourceRatio = size::ratio($this->sourceWidth, $this->sourceHeight);
         $thumbRatio = size::ratio($maxWidth, $maxHeight);
         if ($sourceRatio > $thumbRatio) {
             // fit the height of the source
             $size = size::fit_height($this->sourceWidth, $this->sourceHeight, $maxHeight, true);
         } else {
             // fit the height of the source
             $size = size::fit_width($this->sourceWidth, $this->sourceHeight, $maxWidth, true);
         }
         $this->tmpWidth = $size['width'];
         $this->tmpHeight = $size['height'];
         $this->width = $maxWidth;
         $this->height = $maxHeight;
         return $size;
     }
     // if there's a maxWidth and a maxHeight
     if ($maxWidth && $maxHeight) {
         // if the source width is bigger then the source height
         // we need to fit the width
         if ($this->sourceWidth > $this->sourceHeight) {
             $size = size::fit_width($this->sourceWidth, $this->sourceHeight, $maxWidth, $upscale);
             // do another check for the maxHeight
             if ($size['height'] > $maxHeight) {
                 $size = size::fit_height($size['width'], $size['height'], $maxHeight);
             }
         } else {
             $size = size::fit_height($this->sourceWidth, $this->sourceHeight, $maxHeight, $upscale);
             // do another check for the maxWidth
             if ($size['width'] > $maxWidth) {
                 $size = size::fit_width($size['width'], $size['height'], $maxWidth);
             }
         }
     } elseif ($maxWidth) {
         $size = size::fit_width($this->sourceWidth, $this->sourceHeight, $maxWidth, $upscale);
     } elseif ($maxHeight) {
         $size = size::fit_height($this->sourceWidth, $this->sourceHeight, $maxHeight, $upscale);
     } else {
         $size = array('width' => $this->sourceWidth, 'height' => $this->sourceHeight);
     }
     $this->width = $size['width'];
     $this->height = $size['height'];
     return $size;
 }