From 41f3808a195ca7bd28bd8210d9006ecc7b6240c7 Mon Sep 17 00:00:00 2001 From: Manuel Meister Date: Wed, 6 Sep 2023 13:57:32 +0200 Subject: [PATCH] BUGFIX: Respect aspect ratio --- Classes/Domain/AbstractScalableImageSource.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Classes/Domain/AbstractScalableImageSource.php b/Classes/Domain/AbstractScalableImageSource.php index 580a16e..2ce5e47 100644 --- a/Classes/Domain/AbstractScalableImageSource.php +++ b/Classes/Domain/AbstractScalableImageSource.php @@ -44,7 +44,11 @@ public function withWidth(int $targetWidth = null, bool $preserveAspect = false) $newSource = clone $this; $newSource->targetWidth = $targetWidth; if ($preserveAspect === true) { - $aspect = ($this->targetWidth ?: $this->baseWidth) / ($this->targetHeight ?: $this->baseHeight); + if ($this->targetWidth && $this->targetHeight) { + $aspect = $this->targetWidth / $this->targetHeight; + } else { + $aspect = $this->baseWidth / $this->baseHeight; + } $newSource->targetHeight = (int) round($targetWidth / $aspect); } @@ -62,7 +66,11 @@ public function withHeight(int $targetHeight = null, bool $preserveAspect = fals $newSource = clone $this; $newSource->targetHeight = $targetHeight; if ($preserveAspect === true) { - $aspect = ($this->targetWidth ?: $this->baseWidth) / ($this->targetHeight ?: $this->baseHeight); + if ($this->targetWidth && $this->targetHeight) { + $aspect = $this->targetWidth / $this->targetHeight; + } else { + $aspect = $this->baseWidth / $this->baseHeight; + } $newSource->targetWidth = (int) round($targetHeight * $aspect); }