Skip to content

Commit

Permalink
Cast int for dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jonom committed Jan 17, 2018
1 parent 092c47f commit 0e44ef2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/FocusPointImageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,18 @@ public function FocusFill($width, $height, $upscale = true)
{
$width = intval($width);
$height = intval($height);
$imgW = $this->owner->getWidth();
$imgH = $this->owner->getHeight();
// Don't enlarge
if (!$upscale) {
$widthRatio = $this->owner->width / $width;
$heightRatio = $this->owner->height / $height;
$widthRatio = $imgW / $width;
$heightRatio = $imgH / $height;
if ($widthRatio < 1 && $widthRatio <= $heightRatio) {
$width = $this->owner->width;
$height = round($height * $widthRatio);
$width = $imgW;
$height = intval(round($height * $widthRatio));
} elseif ($heightRatio < 1) {
$height = $this->owner->height;
$width = round($width * $heightRatio);
$height = $imgH;
$width = intval(round($width * $heightRatio));
}
}
//Only resize if necessary
Expand Down

0 comments on commit 0e44ef2

Please sign in to comment.