Skip to content

Commit 92f3789

Browse files
authored
Merge pull request plone#1536 from plone/image-handling-image-scales-from-brain
Add section "Image scales from brain" to Classic UI > Image handling
2 parents bcad63a + 9f67267 commit 92f3789

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/classic-ui/images.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,53 @@ This will result in a `srcset` as in the following example for a medium image:
460460
Please note that this example has the `resolve_uid_and_caption` filter disabled to see the scale names better.
461461
The real `src` URLs look more like `http://localhost:8080/Plone50/dsc04791.jpg/@@images/778f9c06-36b0-485d-ab80-12c623dc4bc3.jpeg`.
462462
```
463+
464+
## Image scales from catalog brain
465+
466+
For all `NamedBlobImage` fields, we can get existing scale information directly from the catalog brain.
467+
468+
Given a content type with a `NamedBlobField` named `picture`, we can get the following information by calling the `image_scales` attribute on the catalog brain.
469+
470+
```python
471+
(Pdb) pp brain.image_scales
472+
{'picture': [{'content-type': 'image/jpeg',
473+
'download': '@@images/picture-800-ddae07fbc46b293155bd6fcda7f2572a.jpeg',
474+
'filename': 'my-picture.jpg',
475+
'height': 800,
476+
'scales': {'icon': {'download': '@@images/picture-32-f2f815374aa5434e06fb3a95306527fd.jpeg',
477+
'height': 32,
478+
'width': 32},
479+
'large': {'download': '@@images/picture-800-4dab3b3cc42abb6fad29258c7430070a.jpeg',
480+
'height': 800,
481+
'width': 800},
482+
'listing': {'download': '@@images/picture-16-d3ac2117158cf38d0e15c5f5feb8b75d.jpeg',
483+
'height': 16,
484+
'width': 16},
485+
'mini': {'download': '@@images/picture-200-3de96ae4288dfb18f5589c89b861ecc1.jpeg',
486+
'height': 200,
487+
'width': 200},
488+
'preview': {'download': '@@images/picture-400-60f60942c8e4ddd7dcdfa90527a8bae0.jpeg',
489+
'height': 400,
490+
'width': 400},
491+
'teaser': {'download': '@@images/picture-600-1ada88b8af6748e9cbe18a34c3127443.jpeg',
492+
'height': 600,
493+
'width': 600},
494+
'thumb': {'download': '@@images/picture-128-80fce253497f7a745315f58f3e8f3a0c.jpeg',
495+
'height': 128,
496+
'width': 128},
497+
'tile': {'download': '@@images/picture-64-220d6703eac104c59774a379a8276e76.jpeg',
498+
'height': 64,
499+
'width': 64}},
500+
'size': 238977,
501+
'width': 800}]}
502+
```
503+
504+
This information shows we have everything we need to generate our image URLs, without waking up any objects.
505+
506+
```xml
507+
<li tal:define="preview python: brain.image_scales['picture'][0]['scales']['preview']">
508+
<img src="${brain/getURL}/${python: preview['download']}"
509+
width="${python: preview['width']}"
510+
height="${python: preview['height']}" />
511+
</li>
512+
```

0 commit comments

Comments
 (0)