Skip to content

Commit c384e97

Browse files
authored
Merge branch '6-dev' into organize-navigation-restapi
2 parents 9847632 + 4f0fb89 commit c384e97

File tree

4 files changed

+184
-58
lines changed

4 files changed

+184
-58
lines changed

docs/classic-ui/images.md

Lines changed: 181 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ We will use the image object as context in the following examples.
2525

2626
## Default scales
2727

28-
In `/@@imaging-controlpanel` Plone allows you to configure which scales are available and what dimensions they should have. By default we have the following scales configured:
28+
In `/@@imaging-controlpanel` Plone allows you to configure which scales are available and what dimensions they should have.
29+
By default, we have the following scales configured:
2930

3031
* huge 1600:65536
3132
* great 1200:65536
@@ -176,9 +177,9 @@ scale_util = api.content.get_view("images", context, request)
176177
tag = scale_util.scale("image", width=600, height=200)
177178
```
178179

179-
(classic-ui-images-using-image_scale0-in-templates-label)=
180+
(classic-ui-images-using-image_scale-in-templates-label)=
180181

181-
### Using image_scale in templates
182+
### Using `image_scale` in templates
182183

183184
You could use the URL-variant from above, but that would be an uncached version.
184185
To create a cached scale in a page template you can do the following:
@@ -212,9 +213,10 @@ You can also provide the following keyword arguments to set `title`, `alt`, or `
212213

213214
(classic-ui-images-get-image_scale-by-cached-uid-name-label)=
214215

215-
### Get image_scale by cached UID name
216+
### Get `image_scale` by cached UID name
216217

217-
If you only have the cached image name from an URL and need to get the image scale, unfortunately you can't use restrictedTraverse(), as this will not be able to resolve the scale. But you can use this workaround, by calling the `publishTraverse` method in `ImageScaling` directly:
218+
If you only have the cached image name from an URL and need to get the image scale, unfortunately you can't use `restrictedTraverse()`, as this will not be able to resolve the scale.
219+
But you can use this workaround, by calling the `publishTraverse` method in `ImageScaling` directly:
218220

219221
```python
220222
import re
@@ -255,81 +257,206 @@ The `ImageScaling` view explicitly checks the permissions of the current user.
255257
To access image scales, which are normally not accessible to the current user, override the `validate_access` method in `plone.namedfile.scaling.ImageScale`.
256258

257259

258-
## `srcset` configuration
260+
(classic-ui-images-responsive-image-support)=
259261

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

264+
Plone supports the generation of picture tags with `srcset`s for image optimization.
265+
Additionally, you can define [media queries](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries) for [art direction](classic-ui-images-responsive-image-support-art-direction) and further optimization.
264266

265-
### viewport size
267+
The configuration allows you to define different picture variants, such as `Large`, `Medium`, or `Small`.
268+
Users can choose from them in editors, such as TinyMCE, and developers can use them in templates.
266269

267-
The first is metric would be the viewport size.
270+
271+
(classic-ui-images-responsive-image-support-picture-variants)=
272+
273+
### Picture variants
274+
275+
In `/@@imaging-controlpanel` Plone allows you to define picture variants with a list of available image scales.
276+
These are used for HTML {term}`srcset` attributes.
277+
A `srcset` attribute can help the browser to serve the best fitting image size for the current user's display.
278+
279+
280+
(classic-ui-images-responsive-image-support-default-configuration-label)=
281+
282+
### Default configuration
283+
284+
The default configuration covers image size optimization, and will provide the browser with the needed information to load the optimal image size.
268285

269286
```json
270287
{
271-
"scale": "large",
272-
"media": "(max-width:800px)"
273-
},
288+
"large": {
289+
"title": "Large",
290+
"sourceset": [
291+
"scale": "larger",
292+
"additionalScales": ["preview", "teaser", "large", "great", "huge"],
293+
],
294+
},
295+
"medium": {
296+
"title": "Medium",
297+
"sourceset": [
298+
"scale": "teaser",
299+
"additionalScales": ["preview", "large", "larger", "great"],
300+
],
301+
},
302+
"small": {
303+
"title": "Small",
304+
"sourceset": [
305+
"scale": "preview",
306+
"additionalScales": ["large", "larger"],
307+
],
308+
},
309+
}
310+
```
311+
312+
### Optional settings
313+
314+
The `sourceset` property is an array and can have more than one entry.
315+
If we have the following two entries, the `image_srcset` output filter will generate one `source` tag for each entry and an additional `img` tag from the last entry.
316+
317+
```json
274318
{
275-
"scale": "larger"
319+
"medium": {
320+
"title": "Large",
321+
"sourceset": [
322+
{
323+
"scale": "mobile_crop",
324+
"media": "(max-width: 768px)",
325+
"additionalScales": ["mobile_crop_highres"],
326+
},
327+
{
328+
"scale": "teaser",
329+
"media": "(min-width: 769px)",
330+
"additionalScales": ["large", "larger", "great", "huge"],
331+
}
332+
],
333+
},
276334
}
277335
```
278336

279-
With this definition the browser will use the `large` scale when the viewport's width is 800 pixels or fewer.
280-
When the viewport width is greater than 800 pixels, the browser will use the larger scale `1000px`.
281337

338+
(classic-ui-images-responsive-image-support-filtering-scales)=
282339

283-
### Pixel density
340+
#### Filtering scales
284341

285-
Another metric is the pixel density of the user's screen.
286-
This metric denotes the pixel density, or resolution, of an output device in {term}`dots per inch` (DPI).
342+
By default, for every `srcset`, all available scales will be included in the `srcset`.
287343

288344
```json
289345
{
290-
"scale": "huge",
291-
"media": "(min-resolution: 192dpi), (-webkit-min-device-pixel-ratio: 2)"
292-
},
293-
{
294-
"scale": "large"
346+
"large": {
347+
"title": "Large",
348+
"sourceset": [
349+
{"scale": "larger"},
350+
],
351+
},
295352
}
296353
```
297354

298-
With this definition the browser will use the `huge` scale of 1600 pixels when the screen has a density of 192 DPI, also knows as `2x`.
299-
We use here two different media queries to also support older Safari versions.
300-
Mobile devices with Safari-like iPhones only support the old non-standard media query.
301-
If you do not care about IE support, you can use `min-resolution: 2dppx`, which is closer to `2x`.
302-
The most common variants are:
355+
To restrict the list of used scales inside a `srcset`, you can set the `additionalScales` parameter with an array of allowed scales.
356+
Without this parameter, all scales which are not globally excluded scales will be used.
357+
358+
```json
359+
"small": {
360+
"title": "Small",
361+
"sourceset": [
362+
{
363+
"scale": "preview",
364+
"additionalScales": ["large", "larger", "great", "huge"],
365+
},
366+
],
367+
},
368+
```
369+
370+
This means the generated `srcset` will contain the scales from `preview` up to `huge`, but not `mini`, for example.
303371

304-
- `1x`: 96 DPI
305-
- `1.25x`: 120 DPI
306-
- `1.5x`: 144 DPI
307-
- `2x`: 192 DPI
308-
- `3x`: 288 DPI
309372

373+
(classic-ui-images-responsive-image-support-picture-variant-in-editor)=
310374

311-
### Combining viewport size and pixel density
375+
#### Hiding a picture variant in editors
312376

313-
It is also possible to combine the two metrics.
377+
It is possible to hide a picture variant in editors.
378+
This is useful when you want to define a picture variant to be used in templates only.
379+
380+
```json
381+
"leadimage": {
382+
"title": "Lead image",
383+
"sourceset": [
384+
{
385+
"scale": "preview",
386+
"additionalScales": ["large", "larger"],
387+
"hideInEditor": true,
388+
},
389+
],
390+
},
391+
```
392+
393+
394+
(classic-ui-images-responsive-image-support-art-direction)=
395+
396+
### Art direction
397+
398+
With image size optimization, the browser is able to choose the optimal image for each display size.
399+
But we have no control over which scale the browser will actually use.
400+
For example to force the browser to use a zoomed version of an image for smaller screens, we can use media queries.
401+
The technique is called [art direction](https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#art_direction).
402+
403+
Let's have a look at a more advanced configuration:
314404

315405
```json
316406
{
317-
"scale": "great",
318-
"media": "(max-width:799px) and (min-resolution: 144dpi), (max-width:799px) and (-webkit-min-device-pixel-ratio: 1.5)"
319-
},
320-
{
321-
"scale": "large",
322-
"media": "(max-width:799px)"
323-
},
324-
{
325-
"scale": "huge",
326-
"media": "(min-width:800px) and (min-resolution: 144dpi), (max-width:800px) and (-webkit-min-device-pixel-ratio: 1.5)"
327-
},
328-
{
329-
"scale": "larger",
330-
"media": "(min-width:800px)"
331-
},
332-
{
333-
"scale": "huge"
407+
"large": {
408+
"title": "Large",
409+
"sourceset": [
410+
{"scale": "larger"},
411+
],
412+
},
413+
"medium": {
414+
"title": "Medium",
415+
"sourceset": [
416+
{
417+
"scale": "mobile_crop",
418+
"media": "(max-width: 768px)",
419+
"additionalScales": ["mobile_crop_highres"],
420+
},
421+
{
422+
"scale": "teaser",
423+
"media": "(min-width: 769px)",
424+
"additionalScales": ["large", "larger", "great", "huge"],
425+
}
426+
],
427+
},
428+
"small": {
429+
"title": "Small",
430+
"sourceset": [
431+
{"scale": "preview"},
432+
],
433+
},
334434
}
435+
436+
```
437+
438+
This will result in a `srcset` as in the following example for a medium image:
439+
440+
```html
441+
<picture>
442+
<source media="(max-width: 677px)"
443+
srcset="resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/mobile_crop 800w,
444+
resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/mobile_crop_highres 1600w">
445+
<source media="(min-width: 678px)"
446+
srcset="resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/teaser 600w,
447+
resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/large 800w,
448+
resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/larger 1000w,
449+
resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/great 1200w">
450+
<img alt="Alternative text"
451+
class="image-richtext image-size-medium"
452+
loading="lazy"
453+
src="resolveuid/45fed06defa54d15b37c5b1dc882710c/@@images/image/teaser"
454+
width="600"
455+
height="400">
456+
</picture>
457+
```
458+
459+
```{note}
460+
Please note that this example has the `resolve_uid_and_caption` filter disabled to see the scale names better.
461+
The real `src` URLs look more like `http://localhost:8080/Plone50/dsc04791.jpg/@@images/778f9c06-36b0-485d-ab80-12c623dc4bc3.jpeg`.
335462
```

docs/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@
129129

130130
html_static_path = [
131131
"_static",
132-
"volto/_static/*.png",
133-
"volto/_static/*.jpg",
132+
"volto/_static/volto/img",
134133
]
135134

136135
# -- Options for myST markdown conversion to html -----------------------------

submodules/plone.restapi

Submodule plone.restapi updated 101 files

0 commit comments

Comments
 (0)