From 42511ebb779f62e08fc1df022440b87182ef86e5 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Wed, 26 Sep 2018 11:04:53 -0400 Subject: [PATCH] Additional tweak for processwire/processwire-issues#709 --- wire/core/Pageimage.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/wire/core/Pageimage.php b/wire/core/Pageimage.php index fd9c0b1c..59b05721 100644 --- a/wire/core/Pageimage.php +++ b/wire/core/Pageimage.php @@ -1017,11 +1017,19 @@ class Pageimage extends Pagefile { */ public function maxSize($width, $height, $options = array()) { - if($width < 1 || $this->width() <= $width) $width = 0; - if($height < 1 || $this->height() <= $height) $height = 0; + $adjustedWidth = $width < 1 || $this->width() <= $width ? 0 : $width; + $adjustedHeight = $height < 1 || $this->height() <= $height ? 0 : $height; // if already within maxSize dimensions then do nothing - if(!$width && !$height) return $this; + if(!$adjustedWidth && !$adjustedHeight) { + if(empty($options)) return $this; // image already within target + $adjustedWidth = $width; + $options['nameHeight'] = $height; + } else if(!$adjustedWidth) { + $options['nameWidth'] = $width; + } else if(!$adjustedHeight) { + $options['nameHeight'] = $height; + } $options['upscaling'] = false; $options['cropping'] = false; @@ -1034,7 +1042,7 @@ class Pageimage extends Pagefile { $options['suffix'] = $suffix; } - return $this->size($width, $height, $options); + return $this->size($adjustedWidth, $adjustedHeight, $options); } /**