Skip to content

Commit

Permalink
TASK: Introduce ScalableImageSourceHelperInterface to make the implem…
Browse files Browse the repository at this point in the history
…entation of scale optional
  • Loading branch information
mficzel committed Jul 13, 2018
1 parent 7cf7f44 commit 6343116
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 25 deletions.
31 changes: 20 additions & 11 deletions Classes/EelHelpers/AbstractImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@ public function applyPreset(string $name) : ImageSourceHelperInterface
*/
public function widthSrcset(array $widthSet): string
{
$srcsetArray = [];
foreach ($widthSet as $targetWidth) {
$scaleFactor = $targetWidth / $this->getWidth();
$scaled = $this->scale($scaleFactor);
$srcsetArray[] = $scaled->src() . ' ' . $targetWidth . 'w';
if ($this instanceof ScalableImageSourceHelperInterface) {
$srcsetArray = [];
foreach ($widthSet as $targetWidth) {
$scaleFactor = $targetWidth / $this->getWidth();
$scaled = $this->scale($scaleFactor);
$srcsetArray[] = $scaled->src() . ' ' . $targetWidth . 'w';
}
return implode(', ', $srcsetArray);
} else {
return $this->src();
}
return implode(', ', $srcsetArray);

}

/**
Expand All @@ -89,12 +94,16 @@ public function widthSrcset(array $widthSet): string
*/
public function resolutionSrcset(array $resolutionSet): string
{
$srcsetArray = [];
foreach ($resolutionSet as $scaleFactor) {
$scaled = $this->scale($scaleFactor);
$srcsetArray[] = $scaled->src() . ' ' . $scaleFactor . 'x';
if ($this instanceof ScalableImageSourceHelperInterface) {
$srcsetArray = [];
foreach ($resolutionSet as $scaleFactor) {
$scaled = $this->scale($scaleFactor);
$srcsetArray[] = $scaled->src() . ' ' . $scaleFactor . 'x';
}
return implode(', ', $srcsetArray);
} else {
return $this->src();
}
return implode(', ', $srcsetArray);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Classes/EelHelpers/AssetImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Neos\Media\Domain\Model\ThumbnailConfiguration;
use Neos\Flow\Mvc\ActionRequest;

class AssetImageSourceHelper extends AbstractImageSourceHelper
class AssetImageSourceHelper extends AbstractImageSourceHelper implements ScalableImageSourceHelperInterface
{

/**
Expand Down Expand Up @@ -47,6 +47,7 @@ public function __construct(ImageInterface $asset)
$this->asset = $asset;
}


/**
* @param bool $async
*/
Expand Down
2 changes: 1 addition & 1 deletion Classes/EelHelpers/DummyImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Neos\Flow\Annotations as Flow;

class DummyImageSourceHelper extends AbstractImageSourceHelper
class DummyImageSourceHelper extends AbstractImageSourceHelper implements ScalableImageSourceHelperInterface
{
protected $baseWidth = 600;

Expand Down
2 changes: 0 additions & 2 deletions Classes/EelHelpers/ImageSourceHelperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public function setHeight(int $height = null) : ImageSourceHelperInterface;

public function applyPreset(string $name) : ImageSourceHelperInterface;

public function scale(float $factor): ImageSourceHelperInterface;

public function src() : string;

public function widthSrcset(array $widthSet) : string;
Expand Down
5 changes: 0 additions & 5 deletions Classes/EelHelpers/ResourceImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public function __construct(string $package, string $path)
$this->path = $path;
}

public function scale(float $factor): ImageSourceHelperInterface
{
return $this;
}

public function src(): string
{
return $this->resourceManager->getPublicPackageResourceUri($this->package, $this->path);
Expand Down
7 changes: 7 additions & 0 deletions Classes/EelHelpers/ScalableImageSourceHelperInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace Sitegeist\Kaleidoscope\EelHelpers;

interface ScalableImageSourceHelperInterface extends ImageSourceHelperInterface
{
public function scale(float $factor): ImageSourceHelperInterface;
}
5 changes: 0 additions & 5 deletions Classes/EelHelpers/UriImageSourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ public function __construct(string $uri)
$this->uri = $uri;
}

public function scale(float $factor): ImageSourceHelperInterface
{
return $this;
}

public function src(): string
{
return $this->uri;
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ We want to help implementing responsive-images in the context of atomic-fusion
and enable previewing fusion-components and their full responsive behavior in the
Sitegeist.Monocle living styleguide.

Sitegeist.Kaleidoscope comes with Fusion-ImageSources for Assets, DummyImages, Resources
and static Uris.

### Authors & Sponsors

* Martin Ficzel - [email protected]
Expand Down

0 comments on commit 6343116

Please sign in to comment.