From c5b8abcaf0bb8998edf08d7324dcfed356af9366 Mon Sep 17 00:00:00 2001 From: Matthew Exon Date: Sat, 6 Apr 2024 05:08:07 +0100 Subject: [PATCH] round scaled dimensions up to avoid zero size --- src/Object/Image.php | 3 +++ src/Util/Images.php | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Object/Image.php b/src/Object/Image.php index bff1efccbe..6e1b2fe8f8 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -591,6 +591,9 @@ class Image if (!$this->isValid()) { return false; } + if ($dest_width <= 0 || $dest_height <= 0) { + return false; + } if ($this->isImagick()) { /* diff --git a/src/Util/Images.php b/src/Util/Images.php index f5a7e5af3d..dac6f15aec 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -418,19 +418,19 @@ class Images if ((($height * 9) / 16) > $width) { $dest_width = $max; - $dest_height = intval(($height * $max) / $width); + $dest_height = intval(ceil(($height * $max) / $width)); } elseif ($width > $height) { // else constrain both dimensions $dest_width = $max; - $dest_height = intval(($height * $max) / $width); + $dest_height = intval(ceil(($height * $max) / $width)); } else { - $dest_width = intval(($width * $max) / $height); + $dest_width = intval(ceil(($width * $max) / $height)); $dest_height = $max; } } else { if ($width > $max) { $dest_width = $max; - $dest_height = intval(($height * $max) / $width); + $dest_height = intval(ceil(($height * $max) / $width)); } else { if ($height > $max) { // very tall image (greater than 16:9) @@ -440,7 +440,7 @@ class Images $dest_width = $width; $dest_height = $height; } else { - $dest_width = intval(($width * $max) / $height); + $dest_width = intval(ceil(($width * $max) / $height)); $dest_height = $max; } } else {