You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The default content types and behaviors are using a `plone.namedfile.NamedBlobImage` field for all images.
14
+
15
+
For this fields, image scaling and HTML tag creation is provided by the `plone.namedfile.scaling` module, specifically in the [`ImageScaling`](https://github.com/plone/plone.namedfile/blob/ecf33a2bc7a8c61888909bc383b3e08d80888e43/plone/namedfile/scaling.py#L350) view.
16
+
17
+
Given a Dexterity content type named `news-item1` with a `plone.namedfile.NamedBlobImage` field named `image`, we can use the following API's to access the image scales and manage scales.
18
+
```{note}
19
+
We will use the image object as context in the following examples.
20
+
```
21
+
22
+
## Default scales
23
+
24
+
Plone allows you in the `/@@imaging-controlpanel` to configure which scales are available and what dimensions they should have. By default we have the following scales configured:
25
+
26
+
* large 768:768
27
+
* preview 400:400
28
+
* mini 200:200
29
+
* thumb 128:128
30
+
* tile 64:64
31
+
* icon 32:32
32
+
* listing 16:16
33
+
34
+
You can add or change scale as you like.
35
+
36
+
37
+
## Image resolving by URI
38
+
39
+
Plone can resolve an image scale via URI in different ways.
40
+
41
+
### By field and scale name
42
+
43
+
Given our `news-item1` with the field `image`, we can get the name scale `thumb` as follows:
This very useful for caching URL's in Varnish or the Browser. In case the scale definitions have changed, they will be saved again under a different UID, so that the URL will change and enforce the Browser or a cache proxy like Varnish to fetch it again.
14
60
15
61
16
62
(classic-ui-images-image-tag-label)=
@@ -23,7 +69,7 @@ To get an HTML tag for a scaled image, you can use the `ImageScaling` view as fo
tag = scale_util.scale("leadimage", width="600", height="200")
153
+
tag = scale_util.scale("image", width="600", height="200")
154
+
```
155
+
156
+
### Using image_scale in templates
157
+
158
+
You could use the URL-variant from above, but that would be an an uncached version. To create a cached scale in a page template you can do the following:
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:
190
+
191
+
```python
192
+
import re
193
+
from plone import api
194
+
195
+
uri ="http://localhost:8080/Plone/news-item1/@@images/3d182f34-8773-4f20-a79d-8774c3151b7e.jpeg"
## Scaling `direction` deprecated in favor of `mode`
208
+
## Scaling `direction`
113
209
114
-
The actual scaling is done in `plone.scale`.
115
-
In Plone 6 in `plone.scale`, the `direction` argument is deprecated in favor of `mode`.
116
-
The values should be converted as follows:
210
+
The default direction is `thumbnail`.
117
211
118
-
direction values | mode values
119
-
-----------------|------------
120
-
scale-crop-to-fit | contain
121
-
down | contain
122
-
scale-crop-to-fill | cover
123
-
up | cover
124
-
keep | scale
125
-
thumbnail | scale
212
+
Other options are:
126
213
127
-
For now `plone.namedfile` still expects the `direction` argument with the old values.
214
+
* scale-crop-to-fit
215
+
* down
216
+
* scale-crop-to-fill
217
+
* up
218
+
* keep
219
+
* thumbnail
128
220
129
221
130
222
(classic-ui-images-permissions-label)=
131
223
132
224
## Permissions
133
225
134
226
The `ImageScaling` view explicitly checks the permissions of the current user.
135
-
To access image scales which are normally not accessible to the current user override the `validate_access` method in `plone.namedfile.scaling.ImageScale`.
136
-
In `Products.EasyNewsletter` you can find an example of that.
227
+
To access image scales which are normally not accessible to the current user, override the `validate_access` method in `plone.namedfile.scaling.ImageScale`.
0 commit comments