Skip to content

Commit

Permalink
BUGFIX: Add getCurrentWidthMethods to scalable sources again for calc…
Browse files Browse the repository at this point in the history
…ulations
  • Loading branch information
mficzel committed Jul 16, 2018
1 parent c9d3844 commit 699dad8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Classes/EelHelpers/AbstractImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
23 changes: 23 additions & 0 deletions Classes/EelHelpers/AssetImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
10 changes: 5 additions & 5 deletions Classes/EelHelpers/DummyImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -107,7 +107,7 @@ public function getWidth() : int
}


public function getHeight() : int
public function getCurrentHeight() : int
{
if ($this->targetHeight) {
return $this->targetHeight;
Expand Down
4 changes: 4 additions & 0 deletions Classes/EelHelpers/ScalableImageSourceHelperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
interface ScalableImageSourceHelperInterface extends ImageSourceHelperInterface
{
public function scale(float $factor): ImageSourceHelperInterface;

public function getCurrentWidth() : int;

public function getCurrentHeight() : int;
}

0 comments on commit 699dad8

Please sign in to comment.