Skip to content

Commit a6a3e35

Browse files
authored
Merge pull request #75 from jonnitto/feature/quality
FEATURE: Add quality option
2 parents e0ed8f4 + ff05f70 commit a6a3e35

File tree

10 files changed

+61
-2
lines changed

10 files changed

+61
-2
lines changed

Classes/Domain/AbstractImageSource.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ abstract class AbstractImageSource implements ImageSourceInterface, ProtectedCon
2626
*/
2727
protected $targetHeight;
2828

29+
/**
30+
* @var int|null
31+
*/
32+
protected $targetQuality;
33+
2934
/**
3035
* @var string|null
3136
*/
@@ -105,6 +110,22 @@ public function withHeight(int $targetHeight, bool $preserveAspect = false): Ima
105110
return $newSource;
106111
}
107112

113+
/**
114+
* @deprecated
115+
*/
116+
public function setQuality(int $quality): ImageSourceInterface
117+
{
118+
return $this->withQuality($quality);
119+
}
120+
121+
public function withQuality(int $quality): ImageSourceInterface
122+
{
123+
$newSource = clone $this;
124+
$newSource->targetQuality = $quality;
125+
126+
return $newSource;
127+
}
128+
108129
/**
109130
* @deprecated
110131
*/
@@ -302,6 +323,7 @@ public function allowsCallOfMethod($methodName)
302323
'withTitle',
303324
'withDimensions',
304325
'withFormat',
326+
'withQuality',
305327
'withWidth',
306328
'withHeight',
307329
'withThumbnailPreset',
@@ -311,6 +333,7 @@ public function allowsCallOfMethod($methodName)
311333
'setHeight',
312334
'setDimensions',
313335
'setFormat',
336+
'setQuality',
314337
'applyPreset',
315338
'applyThumbnailPreset',
316339
'useVariantPreset',

Classes/Domain/AssetImageSource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function src(): string
137137
$allowCropping,
138138
$allowUpScaling,
139139
$async,
140-
null,
140+
$this->targetQuality,
141141
$this->targetFormat
142142
);
143143

@@ -177,7 +177,7 @@ public function dataSrc(): string
177177
$allowCropping,
178178
$allowUpScaling,
179179
$async,
180-
null,
180+
$this->targetQuality,
181181
$this->targetFormat
182182
);
183183

Classes/Domain/ImageSourceInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function withWidth(int $targetWidth, bool $preserveAspect = false): Image
1919

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

22+
public function withQuality(int $targetQuality): ImageSourceInterface;
23+
2224
public function withThumbnailPreset(string $format): ImageSourceInterface;
2325

2426
public function withVariantPreset(string $presetIdentifier, string $presetVariantName): ImageSourceInterface;

Classes/EelHelpers/ImageSourceHelperInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public function setHeight(int $height, bool $preserveAspect = false): ImageSourc
2828
*/
2929
public function setDimensions(int $width, int $height): ImageSourceInterface;
3030

31+
/**
32+
* @deprecated use withQuality
33+
*/
34+
public function setQuality(int $quality): ImageSourceInterface;
35+
3136
/**
3237
* @deprecated use withFormat
3338
*/

Classes/FusionObjects/AbstractImageSourceImplementation.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ public function getHeight(): ?int
2525
return $this->fusionValue('height');
2626
}
2727

28+
/**
29+
* @return int|null
30+
*/
31+
public function getQuality(): ?int
32+
{
33+
return $this->fusionValue('quality');
34+
}
35+
2836
/**
2937
* @return string|null
3038
*/
@@ -94,6 +102,10 @@ public function evaluate(): ?ImageSourceInterface
94102
$helper = $helper->withHeight($height);
95103
}
96104

105+
if ($quality = $this->getQuality()) {
106+
$helper = $helper->withQuality($quality);
107+
}
108+
97109
if ($format = $this->getFormat()) {
98110
$helper = $helper->withFormat($format);
99111
}

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Props:
8888
- `sizes`: sizes attribute of the default image (string ot array)
8989
- `loading`: (optional, default "lazy") loading attribute for the img tag
9090
- `format`: (optional) the image-format like `webp` or `png`, will be applied to the `imageSource`
91+
- `quality`: (optional) the image quality from 0 to 100, will be applied to the `imageSource`
9192
- `width`: (optional) the base width, will be applied to the `imageSource`
9293
- `height`: (optional) the base height, will be applied to the `imageSource`
9394
- `alt`: alt-attribute for the img tag (default "")
@@ -136,11 +137,13 @@ Props:
136137
- `media`: (optional) the media attribute for this source
137138
- `type`: (optional) the type attribute for this source
138139
- `format`: (optional) the image-format for the source like `webp` or `png`, is applied to `imageSource` and `type`
140+
- `quality`: (optional) the image quality from 0 to 100, will be applied to the `imageSource`
139141
- `width`: (optional) the base width, will be applied to the `imageSource`
140142
- `height`: (optional) the base height, will be applied to the `imageSource`
141143
- `srcset`: media descriptors like '1.5x' or '600w' of the default image (string ot array)
142144
- `sizes`: sizes attribute of the default image (string ot array)
143145
- `formats`: (optional) image formats that will be rendered as sources of separate type (string or array)
146+
- `quality`: (optional) the image quality from 0 to 100, will be applied to the `imageSource`
144147
- `width`: (optional) the base width, will be applied to the `imageSource`
145148
- `height`: (optional) the base height, will be applied to the `imageSource`
146149
- `loading`: (optional, default "lazy") loading attribute for the img tag
@@ -212,6 +215,7 @@ Props:
212215
- `srcset`: media descriptors like '1.5x' or '600w' of the default image (string ot array, inherited from picture)
213216
- `sizes`: (optional) sizes attribute (string or array, inherited from picture)
214217
- `format`: (optional) the image-format like `webp` or `png`, will be applied to `imageSource` and `type`
218+
- `quality`: (optional) the image quality from 0 to 100, will be applied to the `imageSource`
215219
- `width`: (optional) the base width, will be applied to the `imageSource`
216220
- `height`: (optional) the base height, will be applied to the `imageSource`
217221
- `type`: (optional) the type attribute for the source like `image/png` or `image/webp`, the actual format is enforced via `imageSource.withFormat()`
@@ -307,6 +311,7 @@ Arguments:
307311
- `thumbnailPreset`: `width` and `height` are supported as explained above
308312
- `variantPreset`: as explained above
309313
- `format`: Set the image output format, like webp (default null)
314+
- `quality`: Set the image quality from 0 to 100 (default null)
310315
- `alt`: The alt attribute if not specified otherwise (default null)
311316
- `title`: The title attribute if not specified otherwise (default null)
312317
@@ -355,6 +360,7 @@ Methods of ImageSource-Helpers that are accessible via Eel:
355360
- `withThumbnailPreset( string )`: Set width and/or height via named thumbnail preset from Settings `Neos.Media.thumbnailPresets`
356361
- `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`)
357362
- `withFormat( string )`: Set the image format to generate like `webp`, `png` or `jpeg`
363+
- `withQuality( integer )`: Set the image quality from 0 to 100
358364
- `withAlt( ?string )`: Set the alt atttribute for the image tag
359365
- `withTitle( ?string )`: Set the title atttribute for the image tag
360366
@@ -373,6 +379,7 @@ deprecated methods:
373379
- `setHeight( integer $height, bool $preserveAspect = false )`: Set the intended height
374380
- `setDimensions( integer, interger)`: Set the intended width and height
375381
- `setFormat( string )`: Set the image format to generate like `webp`, `png` or `jpeg`
382+
- `setQuality( integer )`: Set the image quality from 0 to 100
376383
377384
Note: The Eel-helpers cannot be created directly. They have to be created
378385
by using the `Sitegeist.Kaleidoscope:AssetImageSource` or

Resources/Private/Fusion/Prototypes/AssetImageSource.fusion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ prototype(Sitegeist.Kaleidoscope:AssetImageSource) {
88
width = null
99
height = null
1010
format = null
11+
quality = null
1112
}

Resources/Private/Fusion/Prototypes/Image.fusion

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ prototype(Sitegeist.Kaleidoscope:Image) < prototype(Neos.Fusion:Component) {
124124
width = null
125125
height = null
126126
format = null
127+
quality = null
127128
attributes = Neos.Fusion:DataStructure
128129
renderDimensionAttributes = true
129130

@@ -136,6 +137,7 @@ prototype(Sitegeist.Kaleidoscope:Image) < prototype(Neos.Fusion:Component) {
136137
imageSource.@process.applyWidth = ${props.width ? value.withWidth(props.width) : value}
137138
imageSource.@process.applyHeight = ${props.height ? value.withHeight(props.height) : value}
138139
imageSource.@process.applyFormat = ${props.format ? value.withFormat(props.format) : value}
140+
imageSource.@process.applyQuality = ${props.quality ? value.withQuality(props.quality) : value}
139141

140142
srcset = ${props.srcset}
141143
sizes = ${props.sizes}

Resources/Private/Fusion/Prototypes/Picture.fusion

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
5454
loading = 'lazy'
5555
sources = null
5656
formats = null
57+
quality = null
5758
width = null
5859
height = null
5960
alt = ''
@@ -76,6 +77,7 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
7677
__width = ${this.width}
7778
__height = ${this.height}
7879
__format = ${this.format}
80+
__quality = ${this.quality}
7981
}
8082

8183
renderer = Neos.Fusion:Component {
@@ -86,6 +88,7 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
8688
imageSource.@process.applyWidth = ${props.width ? value.setWidth(props.width) : value}
8789
imageSource.@process.applyHeight = ${props.height ? value.setHeight(props.height) : value}
8890
imageSource.@process.applyFormat = ${props.format ? value.setFormat(props.format) : value}
91+
imageSource.@process.applyQuality = ${props.quality ? value.setQuality(props.quality) : value}
8992

9093
srcset = ${props.srcset}
9194
sizes = ${props.sizes}
@@ -111,6 +114,7 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
111114
format={source.format}
112115
width={source.width}
113116
height={source.height}
117+
quality={source.quality}
114118
srcset={source.srcset ? source.srcset : props.srcset}
115119
sizes={source.sizes ? source.sizes : props.sizes}
116120
renderDimensionAttributes={props.renderDimensionAttributes}

Resources/Private/Fusion/Prototypes/Source.fusion

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ prototype(Sitegeist.Kaleidoscope:Source) < prototype(Neos.Fusion:Component) {
1010
width = null
1111
height = null
1212
format = null
13+
quality = null
1314
type = null
1415
media = null
1516
renderDimensionAttributes = true
@@ -19,6 +20,7 @@ prototype(Sitegeist.Kaleidoscope:Source) < prototype(Neos.Fusion:Component) {
1920
@context {
2021
imageSource = ${props.imageSource || __imageSource}
2122
format = ${props.format || __format}
23+
quality = ${props.quality || __quality}
2224
width = ${props.width || __width}
2325
height = ${props.height || __height}
2426
srcset = ${props.srcset || __srcset}
@@ -32,6 +34,7 @@ prototype(Sitegeist.Kaleidoscope:Source) < prototype(Neos.Fusion:Component) {
3234
imageSource.@process.applyWidth = ${width ? value.withWidth(width) : value}
3335
imageSource.@process.applyHeight = ${height ? value.withHeight(height) : value}
3436
imageSource.@process.applyFormat = ${format ? value.withFormat(format) : value}
37+
imageSource.@process.applyQuality = ${quality ? value.withQuality(quality) : value}
3538

3639
type = ${format ? 'image/' + format : props.type}
3740
srcset = ${srcset}

0 commit comments

Comments
 (0)