Skip to content

Fix PageImage::maxSize() not generating the expected file, resulting in a Warning #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions wire/core/Pageimage.php
Original file line number Diff line number Diff line change
Expand Up @@ -1300,19 +1300,23 @@ 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 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(!$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']
&& $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
Expand Down