Skip to content

Commit 0b41803

Browse files
committed
update responsive image docs
1 parent 69fbd6e commit 0b41803

File tree

1 file changed

+60
-30
lines changed

1 file changed

+60
-30
lines changed

docs/classic-ui/images.md

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,11 @@ To access image scales, which are normally not accessible to the current user, o
258258

259259
In `/@@imaging-controlpanel` Plone allows you to define HTML {term}`srcset` attributes.
260260
A `srcset` can help the browser serve the best fitting image for the current users situation.
261-
Which image scale is best for the user can be decided on different metrics.
262261

263262

264263
### default configuration
265264

266-
The default configuration covers image size optimization and will provide the Browser with the needed information to load the optimal image.
265+
The default configuration covers `image size optimization` and will provide the Browser with the needed information to load the optimal image.
267266

268267
```json
269268
{
@@ -290,13 +289,35 @@ The default configuration covers image size optimization and will provide the Br
290289

291290
### optional settings
292291

293-
By default for every srcset all available scales will be included. That mean
292+
The `sourceset` property is an array and can have more than one entry.
293+
If we have the following two entries, the `image_srcset` outputfilter will generate one source-tag for each entry and an additional img-tag from the last entry.
294294

295-
To exclude some scales completely from the srcset definition, one can use `excludeScales`:
295+
```json
296+
{
297+
"medium": {
298+
"title": "Large",
299+
"sourceset": [
300+
{
301+
"scale": "mobile_crop",
302+
"media": "(max-width: 768px)",
303+
"additionalScales": ["mobile_crop_highres"],
304+
},
305+
{
306+
"scale": "teaser",
307+
"media": "(min-width: 769px)",
308+
"additionalScales": ["large", "larger", "great", "huge"],
309+
}
310+
],
311+
},
312+
}
313+
```
314+
315+
#### Filtering scales
316+
317+
By default for every `srcset` all available scales will be included in the `srcset`.
296318

297319
```json
298320
{
299-
"excludedScales": ["tile", "icon", "listing"],
300321
"large": {
301322
"title": "Large",
302323
"sourceset": [
@@ -306,7 +327,7 @@ To exclude some scales completely from the srcset definition, one can use `exclu
306327
}
307328
```
308329

309-
to restrict the list of used scales inside of a srcset, one can set the `additionalScales` parameter with an array of allowed scales.
330+
to restrict the list of used scales inside of a `srcset`, one can set the `additionalScales` parameter with an array of allowed scales.
310331
Without this parameter all scales which are not globally excluded scales will be used.
311332

312333
```json
@@ -321,15 +342,20 @@ Without this parameter all scales which are not globally excluded scales will be
321342
},
322343
```
323344

324-
This means the generated srcset will contain the scales from preview up to huge, but not mini for example.
325-
Another benefit here is that we can define two different source tags with different scales for [art direction](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#art_direction).
326-
This means will force the Browser to deliver a different image for smaller screens.
345+
This means the generated `srcset` will contain the scales from `preview` up to `huge`, but not `mini` for example.
346+
347+
348+
### Art direction
349+
350+
With `image size optimization` the browser is able to choose the optimal image for each situation.
351+
But we have no control lover which scale the browser will actually use.
352+
To force the Browser to use a zoomed version of an image for smaller screens we can use media queries.
353+
The technique is called [art direction](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#art_direction).
327354

328355
Let's have a look at a more advanced configuration:
329356

330357
```json
331358
{
332-
"excludedScales": ["tile", "icon", "listing"],
333359
"large": {
334360
"title": "Large",
335361
"sourceset": [
@@ -339,16 +365,16 @@ Let's have a look at a more advanced configuration:
339365
"medium": {
340366
"title": "Medium",
341367
"sourceset": [
342-
{
343-
"scale": "teaser",
344-
"media": "(min-width: 769px)",
345-
"additionalScales": ["large", "larger", "great", "huge"],
346-
},
347368
{
348369
"scale": "mobile_crop",
349370
"media": "(max-width: 768px)",
350371
"additionalScales": ["mobile_crop_highres"],
351372
},
373+
{
374+
"scale": "teaser",
375+
"media": "(min-width: 769px)",
376+
"additionalScales": ["large", "larger", "great", "huge"],
377+
}
352378
],
353379
},
354380
"small": {
@@ -363,23 +389,27 @@ Let's have a look at a more advanced configuration:
363389

364390
which will result in a srcset like this, for a medium image:
365391

366-
```json
392+
```html
367393
<picture>
368-
<source media="(min-width:800px)"
369-
srcset="https://picsum.photos/id/1011/400 400w,
370-
https://picsum.photos/id/1011/800 800w,
371-
https://picsum.photos/id/1011/1000 1000w,
372-
https://picsum.photos/id/1011/1200 1200w,
373-
https://picsum.photos/id/1011/1600 1600w
374-
"
375-
sizes="400px">
376-
<source media="(max-width:799px)"
377-
srcset="https://picsum.photos/id/1012/800 800w,
378-
https://picsum.photos/id/1012/1000 1000w
379-
"
380-
sizes="96vw">
381-
<img src="https://picsum.photos/id/1011/400" width="400px" height="400px">
394+
<source media="(max-width: 677px)"
395+
srcset="resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/mobile_crop 800w,
396+
resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/mobile_crop_highres 1600w">
397+
<source media="(min-width: 678px)"
398+
srcset="resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/teaser 600w,
399+
resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/large 800w,
400+
resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/larger 1000w,
401+
resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/great 1200w">
402+
<img alt="Alternative text"
403+
class="image-richtext image-size-medium"
404+
loading="lazy"
405+
src="resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/teaser"
406+
width="600"
407+
height="400">
382408
</picture>
383409
```
384410

411+
```{note}
412+
Please notate that this example has the `resolve_uid_and_caption` filter disabled, to see the scale names better.
413+
The real src-urls look more like `http://localhost:8080/Plone50/dsc04791.jpg/@@images/778f9c06-36b0-485d-ab80-12c623dc4bc3.jpeg`
414+
```
385415

0 commit comments

Comments
 (0)