Skip to content

Commit

Permalink
Additional tweak for processwire/processwire-issues#709
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancramerdesign committed Sep 26, 2018
1 parent 42ec0e3 commit 42511eb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions wire/core/Pageimage.php
Original file line number Diff line number Diff line change
Expand Up @@ -1017,11 +1017,19 @@ public function maxHeight($n, array $options = array()) {
*/
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;
Expand All @@ -1034,7 +1042,7 @@ public function maxSize($width, $height, $options = array()) {
$options['suffix'] = $suffix;
}

return $this->size($width, $height, $options);
return $this->size($adjustedWidth, $adjustedHeight, $options);
}

/**
Expand Down

0 comments on commit 42511eb

Please sign in to comment.