Skip to content

Commit 0c836bf

Browse files
authored
Merge pull request plone#1238 from plone/mrtango-images-srcset
Add srcset info to images chapter
2 parents 7db7aa3 + 7299119 commit 0c836bf

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

docs/classic-ui/images.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,83 @@ Other options are:
247247

248248
The `ImageScaling` view explicitly checks the permissions of the current user.
249249
To access image scales, which are normally not accessible to the current user, override the `validate_access` method in `plone.namedfile.scaling.ImageScale`.
250+
251+
252+
## `srcset` configuration
253+
254+
In `/@@imaging-controlpanel` Plone allows you to define HTML {term}`srcset` attributes.
255+
A `srcset` can help the browser serve the best fitting image for the current users situation.
256+
Which image scale is best for the user can be decided on different metrics.
257+
258+
259+
### viewport size
260+
261+
The first is metric would be the viewport size.
262+
263+
```json
264+
{
265+
"scale": "large",
266+
"media": "(max-width:800px)"
267+
},
268+
{
269+
"scale": "larger"
270+
}
271+
```
272+
273+
With this definition the browser will use the `large` scale when the viewport's width is 800 pixels or fewer.
274+
When the viewport width is greater than 800 pixels, the browser will use the larger scale `1000px`.
275+
276+
277+
### Pixel density
278+
279+
Another metric is the pixel density of the user's screen.
280+
This metric denotes the pixel density, or resolution, of an output device in {term}`dots per inch` (DPI).
281+
282+
```json
283+
{
284+
"scale": "huge",
285+
"media": "(min-resolution: 192dpi), (-webkit-min-device-pixel-ratio: 2)"
286+
},
287+
{
288+
"scale": "large"
289+
}
290+
```
291+
292+
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`.
293+
We use here two different media queries to also support older Safari versions.
294+
Mobile devices with Safari-like iPhones only support the old non-standard media query.
295+
If you do not care about IE support, you can use `min-resolution: 2dppx`, which is closer to `2x`.
296+
The most common variants are:
297+
298+
- `1x`: 96 DPI
299+
- `1.25x`: 120 DPI
300+
- `1.5x`: 144 DPI
301+
- `2x`: 192 DPI
302+
- `3x`: 288 DPI
303+
304+
305+
### Combining viewport size and pixel density
306+
307+
It is also possible to combine the two metrics.
308+
309+
```json
310+
{
311+
"scale": "great",
312+
"media": "(max-width:799px) and (min-resolution: 144dpi), (max-width:799px) and (-webkit-min-device-pixel-ratio: 1.5)"
313+
},
314+
{
315+
"scale": "large",
316+
"media": "(max-width:799px)"
317+
},
318+
{
319+
"scale": "huge",
320+
"media": "(min-width:800px) and (min-resolution: 144dpi), (max-width:800px) and (-webkit-min-device-pixel-ratio: 1.5)"
321+
},
322+
{
323+
"scale": "larger",
324+
"media": "(min-width:800px)"
325+
},
326+
{
327+
"scale": "huge"
328+
}
329+
```

docs/glossary.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,21 @@ fence
268268
Open Graph
269269
The [Open Graph protocol](https://ogp.me/) enables any web page to become a rich object in a social graph.
270270
For instance, this is used on Facebook to allow any web page to have the same functionality as any other object on Facebook.
271+
272+
srcset
273+
The [`HTMLImageElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement) property `srcset` is a string which identifies one or more image candidate strings, separated using commas `,`.
274+
Each image candidate string specifies image resources to display in web pages under given circumstances.
275+
276+
```{seealso}
277+
https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/srcset
278+
```
279+
280+
dots per inch
281+
DPI
282+
Represents the number of [dots per inch](https://en.wikipedia.org/wiki/Dots_per_inch).
283+
Screens typically contain 72 or 96 dots per inch.
284+
285+
```{seealso}
286+
https://developer.mozilla.org/en-US/docs/Web/CSS/resolution#dpi
287+
```
271288
```

0 commit comments

Comments
 (0)