From 88a7dd1afba7ee3f7c415251e74b5fd7ccfb866f Mon Sep 17 00:00:00 2001
From: Marek Bachmann <marek.bachmann@comtec.eecs.uni-kassel.de>
Date: Wed, 28 Dec 2022 03:30:56 +0100
Subject: [PATCH 1/3] Replaced the doubled code in for getScalingDimension with
  Images::getScalingDimensions($width, $height,$max)

---
 src/Object/Image.php | 41 ++---------------------------------------
 1 file changed, 2 insertions(+), 39 deletions(-)

diff --git a/src/Object/Image.php b/src/Object/Image.php
index 1d2832f20..430ad6f13 100644
--- a/src/Object/Image.php
+++ b/src/Object/Image.php
@@ -289,45 +289,8 @@ class Image
 			return false;
 		}
 
-		if ($width > $max && $height > $max) {
-			// very tall image (greater than 16:9)
-			// constrain the width - let the height float.
-
-			if ((($height * 9) / 16) > $width) {
-				$dest_width = $max;
-				$dest_height = intval(($height * $max) / $width);
-			} elseif ($width > $height) {
-				// else constrain both dimensions
-				$dest_width = $max;
-				$dest_height = intval(($height * $max) / $width);
-			} else {
-				$dest_width = intval(($width * $max) / $height);
-				$dest_height = $max;
-			}
-		} else {
-			if ($width > $max) {
-				$dest_width = $max;
-				$dest_height = intval(($height * $max) / $width);
-			} else {
-				if ($height > $max) {
-					// very tall image (greater than 16:9)
-					// but width is OK - don't do anything
-
-					if ((($height * 9) / 16) > $width) {
-						$dest_width = $width;
-						$dest_height = $height;
-					} else {
-						$dest_width = intval(($width * $max) / $height);
-						$dest_height = $max;
-					}
-				} else {
-					$dest_width = $width;
-					$dest_height = $height;
-				}
-			}
-		}
-
-		return $this->scale($dest_width, $dest_height);
+		$scale = Images::getScalingDimensions($width, $height,$max);
+		return $this->scale($scale['width'], $scale['height']);
 	}
 
 	/**

From 2c509ac2b297e85560e86bb8a05e8034a9246db2 Mon Sep 17 00:00:00 2001
From: MarekBenjamin <117765478+MarekBenjamin@users.noreply.github.com>
Date: Wed, 28 Dec 2022 16:32:33 +0100
Subject: [PATCH 2/3] Update src/Object/Image.php

Co-authored-by: Hypolite Petovan <hypolite@mrpetovan.com>
---
 src/Object/Image.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Object/Image.php b/src/Object/Image.php
index 430ad6f13..a6436a950 100644
--- a/src/Object/Image.php
+++ b/src/Object/Image.php
@@ -289,7 +289,7 @@ class Image
 			return false;
 		}
 
-		$scale = Images::getScalingDimensions($width, $height,$max);
+		$scale = Images::getScalingDimensions($width, $height, $max);
 		return $this->scale($scale['width'], $scale['height']);
 	}
 

From 7b34fdc7152c75caa8f09ffc3569c55fc7e05598 Mon Sep 17 00:00:00 2001
From: Marek Bachmann <marek.bachmann@comtec.eecs.uni-kassel.de>
Date: Wed, 28 Dec 2022 16:42:38 +0100
Subject: [PATCH 3/3] removed one redundant check for height and width beeing
 set

---
 src/Object/Image.php | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/Object/Image.php b/src/Object/Image.php
index 430ad6f13..67a1af3d1 100644
--- a/src/Object/Image.php
+++ b/src/Object/Image.php
@@ -285,12 +285,13 @@ class Image
 		$width = $this->getWidth();
 		$height = $this->getHeight();
 
-		if ((! $width)|| (! $height)) {
+		$scale = Images::getScalingDimensions($width, $height,$max);
+		if ($scale) {
+			return $this->scale($scale['width'], $scale['height']);
+		} else {
 			return false;
 		}
 
-		$scale = Images::getScalingDimensions($width, $height,$max);
-		return $this->scale($scale['width'], $scale['height']);
 	}
 
 	/**