Skip to content

Commit 4f906e8

Browse files
committed
Add images chapter to classic-ui docs
1 parent 83a35d0 commit 4f906e8

File tree

2 files changed

+112
-2
lines changed

2 files changed

+112
-2
lines changed

docs/classic-ui/images.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
html_meta:
3+
"description": ""
4+
"property=og:description": ""
5+
"property=og:title": ""
6+
"keywords": ""
7+
---
8+
9+
(classic-ui-images-label)=
10+
11+
# Image resolving and scaling
12+
13+
Image scaling is done in plone.namedfile.scaling and most interesting the ImageScaling view.
14+
15+
## Image tag
16+
17+
To get a HTML tag for an scaled image, you can use the ImageScaling view as follow:
18+
19+
```python
20+
from plone import api
21+
22+
scale_util = api.content.get_view('images', context, request)
23+
tag = scale_util.tag('leadimage', scale='mini')
24+
```
25+
26+
or to get a specific size:
27+
28+
```python
29+
from plone import api
30+
31+
scale_util = api.content.get_view('images', context, request)
32+
tag = scale_util.tag('leadimage', width="600", height="200")
33+
```
34+
35+
The first argument is the field name, followed by one of the following arguments:
36+
37+
fieldname=None,
38+
scale=None,
39+
height=None,
40+
width=None,
41+
direction="thumbnail",
42+
43+
44+
## Image scaling without tag creation
45+
46+
To just get the scaling infos, without creating a HTML tag, you can use the ImageScaling view as follow:
47+
48+
```python
49+
from plone import api
50+
51+
scale_util = api.content.get_view('images', context, request)
52+
image_scale = scale_util.scale('leadimage', scale='mini')
53+
print(image_scale.url) # http://localhost:8080/Plone/enl/@@images/3d182f34-8773-4f20-a79d-8774c3151b7e.jpeg
54+
print(image_scale.width) # 200
55+
print(image_scale.height) # 110
56+
```
57+
58+
the most important properties:
59+
60+
- data
61+
- fieldname
62+
- height
63+
- mimetype
64+
- srcset
65+
- srcset_attribute
66+
- tag
67+
- uid
68+
- url
69+
- width
70+
71+
You can get a tag from this point too:
72+
```python
73+
>>> print(image_scale.tag)
74+
75+
<img src="http://localhost:8080/Plone/news/newsitem1/@@images/9f676d46-0cb3-4512-a831-a5db4079bdfa.jpeg" alt="News Item 1!" title="News Item 1" height="21" width="32" srcset="http://localhost:8080/Plone/news/newsitem1/@@images/4a68513c-cffd-4de0-8a35-80627945b80f.jpeg 2x, http://localhost:8080/Plone/news/newsitem1/@@images/c32929c6-cb89-4ce7-846f-38adf29c09a4.jpeg 3x" />
76+
```
77+
78+
or to get a specific size:
79+
80+
```python
81+
from plone import api
82+
83+
scale_util = api.content.get_view('images', context, request)
84+
tag = scale_util.scale('leadimage', width="600", height="200")
85+
```
86+
87+
The first argument is the field name, followed by one of the following arguments:
88+
89+
fieldname=None,
90+
scale=None,
91+
height=None,
92+
width=None,
93+
direction="thumbnail",
94+
95+
## Scaling direction / mode
96+
97+
The actual scaling is done in plone.scale:
98+
In plone scale the `direction` argument is deprecated in favor of `mode` and values are converted as follow:
99+
100+
direction values | mode values
101+
-----------------|------------
102+
scale-crop-to-fit | contain
103+
down | contain
104+
scale-crop-to-fill | cover
105+
up | cover
106+
keep | scale
107+
thumbnail | scale
108+
109+
For now plone.namedfile is still expecting the direction argument with the old values.

docs/classic-ui/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ This frontend is now called "Classic UI".
2727

2828
Choosing one frontend over another depends on several factors.
2929

30-
Classic UI would be a better choice for the following situations.
30+
Classic UI would be a better choice for the following situations.
3131

3232
- Reason 1
3333
- Reason 2
3434
- Reason N
3535

36-
The default frontend Volto would be a better choice for the following situations.
36+
The default frontend Volto would be a better choice for the following situations.
3737

3838
- Reason 1
3939
- Reason 2
@@ -55,6 +55,7 @@ viewlets
5555
forms
5656
portlets
5757
csrf
58+
images
5859
icons
5960
recipes
6061
whatsnew

0 commit comments

Comments
 (0)