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; }