Skip to content

Commit

Permalink
ImageMagick: Fix best fit resize effect
Browse files Browse the repository at this point in the history
Only apply `^` operator (minimum values of size) if both width and height are supplied, otherwise the image will be cropped to a square.
  • Loading branch information
mcaskill committed Jan 30, 2024
1 parent 0bfdd20 commit d94c2b9
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ protected function doResize($width, $height, $bestFit = false)

$size = $width.'x'.$height;
if ($bestFit) {
$params[] = $option.' "'.$size.'^"';
if ($width && $height) {
// Minimum values of width and height given, aspect ratio preserved.
$operator = '^';
} else {
$operator = '';
}

$params[] = $option.' "'.$size.$operator.'"';
$params[] = '-extent '.$size;
} else {
$params[] = $option.' '.$size;
Expand Down

0 comments on commit d94c2b9

Please sign in to comment.