Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into bugfix/#33
Browse files Browse the repository at this point in the history
# Conflicts:
#	Resources/Private/Fusion/Prototypes/Picture.fusion
#	Resources/Private/Fusion/Prototypes/Source.fusion
  • Loading branch information
manuelmeister committed Jun 3, 2024
2 parents 1f6cb4d + a6a3e35 commit 19e2256
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 6 deletions.
23 changes: 23 additions & 0 deletions Classes/Domain/AbstractImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ abstract class AbstractImageSource implements ImageSourceInterface, ProtectedCon
*/
protected $targetHeight;

/**
* @var int|null
*/
protected $targetQuality;

/**
* @var string|null
*/
Expand Down Expand Up @@ -104,6 +109,22 @@ public function withHeight(int $targetHeight, bool $preserveAspect = false): Ima
return $newSource;
}

/**
* @deprecated
*/
public function setQuality(int $quality): ImageSourceInterface
{
return $this->withQuality($quality);
}

public function withQuality(int $quality): ImageSourceInterface
{
$newSource = clone $this;
$newSource->targetQuality = $quality;

return $newSource;
}

/**
* @deprecated
*/
Expand Down Expand Up @@ -277,6 +298,7 @@ public function allowsCallOfMethod($methodName)
'withTitle',
'withDimensions',
'withFormat',
'withQuality',
'withWidth',
'withHeight',
'withThumbnailPreset',
Expand All @@ -286,6 +308,7 @@ public function allowsCallOfMethod($methodName)
'setHeight',
'setDimensions',
'setFormat',
'setQuality',
'applyPreset',
'applyThumbnailPreset',
'useVariantPreset',
Expand Down
26 changes: 20 additions & 6 deletions Classes/Domain/AssetImageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class AssetImageSource extends AbstractScalableImageSource
*/
protected $request;

/**
* Runtime cache for the src uri for the asset.
*
* @var string|null
*/
private $srcCache = null;

/**
* @param ImageInterface $asset
* @param string|null $title
Expand Down Expand Up @@ -112,6 +119,10 @@ public function src(): string
return '';
}

if ($this->srcCache !== null) {
return $this->srcCache;
}

$width = $this->getCurrentWidth();
$height = $this->getCurrentHeight();

Expand All @@ -126,7 +137,7 @@ public function src(): string
$allowCropping,
$allowUpScaling,
$async,
null,
$this->targetQuality,
$this->targetFormat
);

Expand All @@ -136,11 +147,14 @@ public function src(): string
$this->request
);

if ($thumbnailData === null) {
return '';
}
$this->srcCache = ($thumbnailData === null) ? '' : $thumbnailData['src'];

return $thumbnailData['src'];
return $this->srcCache;
}

public function __clone(): void
{
$this->srcCache = null;
}

public function dataSrc(): string
Expand All @@ -163,7 +177,7 @@ public function dataSrc(): string
$allowCropping,
$allowUpScaling,
$async,
null,
$this->targetQuality,
$this->targetFormat
);

Expand Down
2 changes: 2 additions & 0 deletions Classes/Domain/ImageSourceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function withWidth(int $targetWidth, bool $preserveAspect = false): Image

public function withHeight(int $targetHeight, bool $preserveAspect = false): ImageSourceInterface;

public function withQuality(int $targetQuality): ImageSourceInterface;

public function withThumbnailPreset(string $format): ImageSourceInterface;

public function withVariantPreset(string $presetIdentifier, string $presetVariantName): ImageSourceInterface;
Expand Down
5 changes: 5 additions & 0 deletions Classes/EelHelpers/ImageSourceHelperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public function setHeight(int $height, bool $preserveAspect = false): ImageSourc
*/
public function setDimensions(int $width, int $height): ImageSourceInterface;

/**
* @deprecated use withQuality
*/
public function setQuality(int $quality): ImageSourceInterface;

/**
* @deprecated use withFormat
*/
Expand Down
12 changes: 12 additions & 0 deletions Classes/FusionObjects/AbstractImageSourceImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public function getHeight(): ?int
return $this->fusionValue('height');
}

/**
* @return int|null
*/
public function getQuality(): ?int
{
return $this->fusionValue('quality');
}

/**
* @return string|null
*/
Expand Down Expand Up @@ -94,6 +102,10 @@ public function evaluate(): ?ImageSourceInterface
$helper = $helper->withHeight($height);
}

if ($quality = $this->getQuality()) {
$helper = $helper->withQuality($quality);
}

if ($format = $this->getFormat()) {
$helper = $helper->withFormat($format);
}
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Props:
- `sizes`: sizes attribute of the default image (string ot array)
- `loading`: (optional, default "lazy") loading attribute for the img tag
- `format`: (optional) the image-format like `webp` or `png`, will be applied to the `imageSource`
- `quality`: (optional) the image quality from 0 to 100, will be applied to the `imageSource`
- `width`: (optional) the base width, will be applied to the `imageSource`
- `height`: (optional) the base height, will be applied to the `imageSource`
- `alt`: alt-attribute for the img tag (default "")
Expand Down Expand Up @@ -136,11 +137,13 @@ Props:
- `media`: (optional) the media attribute for this source
- `type`: (optional) the type attribute for this source
- `format`: (optional) the image-format for the source like `webp` or `png`, is applied to `imageSource` and `type`
- `quality`: (optional) the image quality from 0 to 100, will be applied to the `imageSource`
- `width`: (optional) the base width, will be applied to the `imageSource`
- `height`: (optional) the base height, will be applied to the `imageSource`
- `srcset`: media descriptors like '1.5x' or '600w' of the default image (string ot array)
- `sizes`: sizes attribute of the default image (string ot array)
- `formats`: (optional) image formats that will be rendered as sources of separate type (string or array)
- `quality`: (optional) the image quality from 0 to 100, will be applied to the `imageSource`
- `width`: (optional) the base width, will be applied to the `imageSource`
- `height`: (optional) the base height, will be applied to the `imageSource`
- `loading`: (optional, default "lazy") loading attribute for the img tag
Expand Down Expand Up @@ -212,6 +215,7 @@ Props:
- `srcset`: media descriptors like '1.5x' or '600w' of the default image (string ot array, inherited from picture)
- `sizes`: (optional) sizes attribute (string or array, inherited from picture)
- `format`: (optional) the image-format like `webp` or `png`, will be applied to `imageSource` and `type`
- `quality`: (optional) the image quality from 0 to 100, will be applied to the `imageSource`
- `width`: (optional) the base width, will be applied to the `imageSource`
- `height`: (optional) the base height, will be applied to the `imageSource`
- `type`: (optional) the type attribute for the source like `image/png` or `image/webp`, the actual format is enforced via `imageSource.withFormat()`
Expand Down Expand Up @@ -307,6 +311,7 @@ Arguments:
- `thumbnailPreset`: `width` and `height` are supported as explained above
- `variantPreset`: as explained above
- `format`: Set the image output format, like webp (default null)
- `quality`: Set the image quality from 0 to 100 (default null)
- `alt`: The alt attribute if not specified otherwise (default null)
- `title`: The title attribute if not specified otherwise (default null)
Expand Down Expand Up @@ -355,6 +360,7 @@ Methods of ImageSource-Helpers that are accessible via Eel:
- `withThumbnailPreset( string )`: Set width and/or height via named thumbnail preset from Settings `Neos.Media.thumbnailPresets`
- `withVariantPreset( string, string )`: Select image variant via the named variant preset (parameters are "preset identifier" key and "preset variant name" key from Settings `Neos.Media.variantPresets`)
- `withFormat( string )`: Set the image format to generate like `webp`, `png` or `jpeg`
- `withQuality( integer )`: Set the image quality from 0 to 100
- `withAlt( ?string )`: Set the alt atttribute for the image tag
- `withTitle( ?string )`: Set the title atttribute for the image tag
Expand All @@ -373,6 +379,7 @@ deprecated methods:
- `setHeight( integer $height, bool $preserveAspect = false )`: Set the intended height
- `setDimensions( integer, interger)`: Set the intended width and height
- `setFormat( string )`: Set the image format to generate like `webp`, `png` or `jpeg`
- `setQuality( integer )`: Set the image quality from 0 to 100
Note: The Eel-helpers cannot be created directly. They have to be created
by using the `Sitegeist.Kaleidoscope:AssetImageSource` or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ prototype(Sitegeist.Kaleidoscope:AssetImageSource) {
width = null
height = null
format = null
quality = null
}
2 changes: 2 additions & 0 deletions Resources/Private/Fusion/Prototypes/Image.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ prototype(Sitegeist.Kaleidoscope:Image) < prototype(Neos.Fusion:Component) {
width = null
height = null
format = null
quality = null
attributes = Neos.Fusion:DataStructure
renderDimensionAttributes = true
allowSrcsetUpScaling = false
Expand All @@ -139,6 +140,7 @@ prototype(Sitegeist.Kaleidoscope:Image) < prototype(Neos.Fusion:Component) {
[email protected] = ${(props.width && !props.height) ? value.withWidth(props.width, props.preserveAspect) : value}
[email protected] = ${(props.height && !props.width) ? value.withHeight(props.height, props.preserveAspect) : value}
[email protected] = ${props.format ? value.withFormat(props.format) : value}
[email protected] = ${props.quality ? value.withQuality(props.quality) : value}

srcset = ${props.srcset}
sizes = ${props.sizes}
Expand Down
4 changes: 4 additions & 0 deletions Resources/Private/Fusion/Prototypes/Picture.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
loading = 'lazy'
sources = null
formats = null
quality = null
width = null
height = null
alt = ''
Expand All @@ -78,6 +79,7 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
__width = ${this.width}
__height = ${this.height}
__format = ${this.format}
__quality = ${this.quality}
}

renderer = Neos.Fusion:Component {
Expand All @@ -89,6 +91,7 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
[email protected] = ${(props.width && !props.height) ? value.withWidth(props.width, props.preserveAspect) : value}
[email protected] = ${(props.height && !props.width) ? value.withHeight(props.height, props.preserveAspect) : value}
[email protected] = ${props.format ? value.withFormat(props.format) : value}
[email protected] = ${props.quality ? value.setQuality(props.quality) : value}

srcset = ${props.srcset}
sizes = ${props.sizes}
Expand Down Expand Up @@ -116,6 +119,7 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
format={source.format}
width={source.width}
height={source.height}
quality={source.quality}
srcset={source.srcset ? source.srcset : props.srcset}
sizes={source.sizes ? source.sizes : props.sizes}
renderDimensionAttributes={props.renderDimensionAttributes}
Expand Down
3 changes: 3 additions & 0 deletions Resources/Private/Fusion/Prototypes/Source.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ prototype(Sitegeist.Kaleidoscope:Source) < prototype(Neos.Fusion:Component) {
width = null
height = null
format = null
quality = null
type = null
media = null
renderDimensionAttributes = true
Expand All @@ -21,6 +22,7 @@ prototype(Sitegeist.Kaleidoscope:Source) < prototype(Neos.Fusion:Component) {
@context {
imageSource = ${props.imageSource || __imageSource}
format = ${props.format || __format}
quality = ${props.quality || __quality}
width = ${props.width || __width}
height = ${props.height || __height}
srcset = ${props.srcset || __srcset}
Expand All @@ -35,6 +37,7 @@ prototype(Sitegeist.Kaleidoscope:Source) < prototype(Neos.Fusion:Component) {
[email protected] = ${(props.width && !props.height) ? value.withWidth(props.width, props.preserveAspect) : value}
[email protected] = ${(props.height && !props.width) ? value.withHeight(props.height, props.preserveAspect) : value}
[email protected] = ${props.format ? value.withFormat(props.format) : value}
[email protected] = ${quality ? value.withQuality(quality) : value}

type = ${format ? 'image/' + format : props.type}
srcset = ${srcset}
Expand Down

0 comments on commit 19e2256

Please sign in to comment.