Skip to content

Commit

Permalink
BUGFIX: Respect aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmeister committed Sep 6, 2023
1 parent ac6f90a commit 41f3808
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Classes/Domain/AbstractScalableImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 41f3808

Please sign in to comment.