From 089a085374b3731ac03cd5e6046ec07d94e761a8 Mon Sep 17 00:00:00 2001 From: Anonymous <> Date: Sat, 22 Jun 2024 14:53:14 +0200 Subject: [PATCH 1/2] Fix maxSize() not generating the expected file if $width == 0, resulting in a Warning --- wire/core/Pageimage.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/wire/core/Pageimage.php b/wire/core/Pageimage.php index 4dcdf5bde..7052a7c0d 100644 --- a/wire/core/Pageimage.php +++ b/wire/core/Pageimage.php @@ -1300,18 +1300,14 @@ public function maxSize($width, $height, $options = array()) { ); $options = array_merge($defaults, $options); - $adjustedWidth = $width < 1 || $this->width() <= $width ? 0 : $width; - $adjustedHeight = $height < 1 || $this->height() <= $height ? 0 : $height; + if($width < 1) $width = 0; + if($height < 1) $height = 0; // if already within maxSize dimensions then do nothing - if(!$adjustedWidth && !$adjustedHeight) { - if($options['allowOriginal']) return $this; // image already within target - $adjustedWidth = $width; - $options['nameHeight'] = $height; - } else if(!$adjustedWidth) { - $options['nameWidth'] = $width; - } else if(!$adjustedHeight) { - $options['nameHeight'] = $height; + if($options['allowOriginal'] + && (!$width || $width >= $this->width()) + && (!$height || $height >= $this->height)) { + return $this; // image already within target } if($this->wire()->config->installed > 1513336849) { @@ -1322,7 +1318,7 @@ public function maxSize($width, $height, $options = array()) { $options['suffix'] = $suffix; } - return $this->size($adjustedWidth, $adjustedHeight, $options); + return $this->size($width, $height, $options); } /** From 5510e76b8b67e96e380e659d159dd0730f244a62 Mon Sep 17 00:00:00 2001 From: Anonymous <> Date: Sat, 22 Jun 2024 15:34:21 +0200 Subject: [PATCH 2/2] Fix maxSize() when both dimensions are unconstrained --- wire/core/Pageimage.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/wire/core/Pageimage.php b/wire/core/Pageimage.php index 7052a7c0d..a0fc10dca 100644 --- a/wire/core/Pageimage.php +++ b/wire/core/Pageimage.php @@ -1303,12 +1303,20 @@ public function maxSize($width, $height, $options = array()) { if($width < 1) $width = 0; if($height < 1) $height = 0; + //if a dimension is unconstrained, set it to the physical size to avoid problems with 0 later + $adjustedWidth = (!$width || $this->width() <= $width) ? $this->width() : $width; + $adjustedHeight = (!$height || $this->height() <= $height) ? $this->height() : $height; + // if already within maxSize dimensions then do nothing if($options['allowOriginal'] - && (!$width || $width >= $this->width()) - && (!$height || $height >= $this->height)) { + && $adjustedWidth == $this->width() + && $adjustedHeight == $this->height()) { return $this; // image already within target } + + //make sure variation is always named after the requested size (0 for unconstrained) + $options['nameWidth'] = $width; + $options['nameHeight'] = $height; if($this->wire()->config->installed > 1513336849) { // New installations from 2017-12-15 forward use an "ms" suffix for images from maxSize() method @@ -1318,7 +1326,7 @@ public function maxSize($width, $height, $options = array()) { $options['suffix'] = $suffix; } - return $this->size($width, $height, $options); + return $this->size($adjustedWidth, $adjustedHeight, $options); } /**