From 699dad86b65e145ab7fd4875bac82f3bf8cc9e72 Mon Sep 17 00:00:00 2001 From: Martin Ficzel Date: Mon, 16 Jul 2018 18:11:04 +0200 Subject: [PATCH] BUGFIX: Add getCurrentWidthMethods to scalable sources again for calculations --- .../EelHelpers/AbstractImageSourceHelper.php | 2 +- Classes/EelHelpers/AssetImageSourceHelper.php | 23 +++++++++++++++++++ Classes/EelHelpers/DummyImageSourceHelper.php | 10 ++++---- .../ScalableImageSourceHelperInterface.php | 4 ++++ 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Classes/EelHelpers/AbstractImageSourceHelper.php b/Classes/EelHelpers/AbstractImageSourceHelper.php index 2daffc2..c1a8891 100644 --- a/Classes/EelHelpers/AbstractImageSourceHelper.php +++ b/Classes/EelHelpers/AbstractImageSourceHelper.php @@ -76,7 +76,7 @@ public function widthSrcset(array $widthSet): string if ($this instanceof ScalableImageSourceHelperInterface) { $srcsetArray = []; foreach ($widthSet as $targetWidth) { - $scaleFactor = $targetWidth / $this->getWidth(); + $scaleFactor = $targetWidth / $this->getCurrentWidth(); $scaled = $this->scale($scaleFactor); $srcsetArray[] = $scaled->src() . ' ' . $targetWidth . 'w'; } diff --git a/Classes/EelHelpers/AssetImageSourceHelper.php b/Classes/EelHelpers/AssetImageSourceHelper.php index 58adf64..9b70b34 100644 --- a/Classes/EelHelpers/AssetImageSourceHelper.php +++ b/Classes/EelHelpers/AssetImageSourceHelper.php @@ -111,4 +111,27 @@ public function src(): string return $thumbnailData['src']; } + + public function getCurrentWidth() : int + { + if ($this->targetWidth) { + return $this->targetWidth; + } elseif ($this->targetHeight) { + return round($this->targetHeight * $this->asset->getWidth() / $this->asset->getHeight()); + } else { + return $this->baseWidth; + } + } + + + public function getCurrentHeight() : int + { + if ($this->targetHeight) { + return $this->targetHeight; + } elseif ($this->targetWidth) { + return round($this->targetWidth * $this->asset->getHeight() / $this->asset->getWidth()); + } else { + return $this->baseHeight; + } + } } diff --git a/Classes/EelHelpers/DummyImageSourceHelper.php b/Classes/EelHelpers/DummyImageSourceHelper.php index 4881146..eaf5050 100644 --- a/Classes/EelHelpers/DummyImageSourceHelper.php +++ b/Classes/EelHelpers/DummyImageSourceHelper.php @@ -85,17 +85,17 @@ public function src(): string { $uri = $this->baseUri . '?' . http_build_query ( [ - 'width' => $this->getWidth(), - 'height' => $this->getHeight(), + 'width' => $this->getCurrentWidth(), + 'height' => $this->getCurrentHeight(), 'backgroundColor' => ($this->backgroundColor ?: '000'), 'foregroundColor' => ($this->foregroundColor ?: 'fff'), - 'text' => ($this->text ?: $this->getWidth() . ' x ' . $this->getHeight()) + 'text' => ($this->text ?: $this->getCurrentWidth() . ' x ' . $this->getCurrentHeight()) ] ); return $uri; } - public function getWidth() : int + public function getCurrentWidth() : int { if ($this->targetWidth) { return $this->targetWidth; @@ -107,7 +107,7 @@ public function getWidth() : int } - public function getHeight() : int + public function getCurrentHeight() : int { if ($this->targetHeight) { return $this->targetHeight; diff --git a/Classes/EelHelpers/ScalableImageSourceHelperInterface.php b/Classes/EelHelpers/ScalableImageSourceHelperInterface.php index d50519e..24cef97 100644 --- a/Classes/EelHelpers/ScalableImageSourceHelperInterface.php +++ b/Classes/EelHelpers/ScalableImageSourceHelperInterface.php @@ -4,4 +4,8 @@ interface ScalableImageSourceHelperInterface extends ImageSourceHelperInterface { public function scale(float $factor): ImageSourceHelperInterface; + + public function getCurrentWidth() : int; + + public function getCurrentHeight() : int; }