round scaled dimensions up to avoid zero size
authorMatthew Exon <mat.github@exon.name>
Sat, 6 Apr 2024 04:08:07 +0000 (05:08 +0100)
committerMatthew Exon <git.mexon@spamgourmet.com>
Sat, 13 Apr 2024 19:50:17 +0000 (21:50 +0200)
src/Object/Image.php
src/Util/Images.php

index bff1efc..6e1b2fe 100644 (file)
@@ -591,6 +591,9 @@ class Image
                if (!$this->isValid()) {
                        return false;
                }
+               if ($dest_width <= 0 || $dest_height <= 0) {
+                       return false;
+               }
 
                if ($this->isImagick()) {
                        /*
index f5a7e5a..dac6f15 100644 (file)
@@ -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 {