Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/source/endpoints/content-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ Here we show `uuid1` as an example uid for all image scales because this documen
When running in a real application, these `uuid1` values will be exchanged by proper uuid4 values.
```

```{note}
The list of scales depends on the allowed image sizes configured in the Image Handling control panel.
Also, scales with a width larger than the original are not included.
```

```{eval-rst}
.. http:example:: curl httpie python-requests
:request: ../../../src/plone/restapi/tests/http-examples/image.req
Expand Down
5 changes: 5 additions & 0 deletions news/+scales.breaking
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The serialization for image fields no longer includes scales with a width larger than the original.
This means that the scales for an image may not include all of the scale sizes defined in the Imaging control panel.
However, this makes them consistent with image scales returned for catalog results,
and avoids unnecessary creation of large scales which add bloat to the database.
@davisagli
5 changes: 5 additions & 0 deletions src/plone/restapi/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def get_scales(context, field, width, height):
images_view = getMultiAdapter((context, request), name="images")

for name, actual_width, actual_height in get_scale_infos():
# Don't offer scales larger than the original.
# They add bloat to the database.
if actual_width > width:
continue

# Recent versions of plone.namedfile support getting scale
# metadata without actually generating the image scale.
# This was added in the same version as the `picture` method,
Expand Down
30 changes: 0 additions & 30 deletions src/plone/restapi/tests/http-examples/image.resp
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,11 @@ Content-Type: application/json
"filename": "image.png",
"height": 56,
"scales": {
"great": {
"download": "http://localhost:55001/plone/image/@@images/uuid1.png",
"height": 56,
"width": 215
},
"huge": {
"download": "http://localhost:55001/plone/image/@@images/uuid1.png",
"height": 56,
"width": 215
},
"icon": {
"download": "http://localhost:55001/plone/image/@@images/uuid1.png",
"height": 8,
"width": 32
},
"large": {
"download": "http://localhost:55001/plone/image/@@images/uuid1.png",
"height": 56,
"width": 215
},
"larger": {
"download": "http://localhost:55001/plone/image/@@images/uuid1.png",
"height": 56,
"width": 215
},
"listing": {
"download": "http://localhost:55001/plone/image/@@images/uuid1.png",
"height": 4,
Expand All @@ -83,16 +63,6 @@ Content-Type: application/json
"height": 52,
"width": 200
},
"preview": {
"download": "http://localhost:55001/plone/image/@@images/uuid1.png",
"height": 56,
"width": 215
},
"teaser": {
"download": "http://localhost:55001/plone/image/@@images/uuid1.png",
"height": 56,
"width": 215
},
"thumb": {
"download": "http://localhost:55001/plone/image/@@images/uuid1.png",
"height": 33,
Expand Down
30 changes: 0 additions & 30 deletions src/plone/restapi/tests/http-examples/newsitem.resp
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,11 @@ Content-Type: application/json
"filename": "image.png",
"height": 56,
"scales": {
"great": {
"download": "http://localhost:55001/plone/newsitem/@@images/uuid1.png",
"height": 56,
"width": 215
},
"huge": {
"download": "http://localhost:55001/plone/newsitem/@@images/uuid1.png",
"height": 56,
"width": 215
},
"icon": {
"download": "http://localhost:55001/plone/newsitem/@@images/uuid1.png",
"height": 8,
"width": 32
},
"large": {
"download": "http://localhost:55001/plone/newsitem/@@images/uuid1.png",
"height": 56,
"width": 215
},
"larger": {
"download": "http://localhost:55001/plone/newsitem/@@images/uuid1.png",
"height": 56,
"width": 215
},
"listing": {
"download": "http://localhost:55001/plone/newsitem/@@images/uuid1.png",
"height": 4,
Expand All @@ -84,16 +64,6 @@ Content-Type: application/json
"height": 52,
"width": 200
},
"preview": {
"download": "http://localhost:55001/plone/newsitem/@@images/uuid1.png",
"height": 56,
"width": 215
},
"teaser": {
"download": "http://localhost:55001/plone/newsitem/@@images/uuid1.png",
"height": 56,
"width": 215
},
"thumb": {
"download": "http://localhost:55001/plone/newsitem/@@images/uuid1.png",
"height": 33,
Expand Down
20 changes: 0 additions & 20 deletions src/plone/restapi/tests/test_dxfield_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,16 +476,6 @@ def test_namedimage_field_serialization_returns_dict_with_original_scale(self):
if HAS_PLONE_6:
# PLIP #3279 amended the image scales
# https://github.com/plone/Products.CMFPlone/pull/3450
scales["great"] = {
"download": scale_download_url,
"height": 768,
"width": 1024,
}
scales["huge"] = {
"download": scale_download_url,
"height": 768,
"width": 1024,
}
scales["larger"] = {
"download": scale_download_url,
"height": 750,
Expand Down Expand Up @@ -603,16 +593,6 @@ def test_namedblobimage_field_serialization_returns_dict_with_original_scale(sel
if HAS_PLONE_6:
# PLIP #3279 amended the image scales
# https://github.com/plone/Products.CMFPlone/pull/3450
scales["great"] = {
"download": scale_download_url,
"height": 768,
"width": 1024,
}
scales["huge"] = {
"download": scale_download_url,
"height": 768,
"width": 1024,
}
scales["larger"] = {
"download": scale_download_url,
"height": 750,
Expand Down
30 changes: 0 additions & 30 deletions src/plone/restapi/tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,37 +277,7 @@ def test_serialize_image(self):
"tile": {"download": download_url, "width": 64, "height": 16},
"thumb": {"download": download_url, "width": 128, "height": 33},
"mini": {"download": download_url, "width": 200, "height": 52},
"preview": {"download": download_url, "width": 215, "height": 56},
"large": {"download": download_url, "width": 215, "height": 56},
}
if HAS_PLONE_6:
# PLIP #3279 amended the image scales
# https://github.com/plone/Products.CMFPlone/pull/3450
scales["great"] = {
"download": download_url,
"height": 56,
"width": 215,
}
scales["huge"] = {
"download": download_url,
"height": 56,
"width": 215,
}
scales["larger"] = {
"download": download_url,
"height": 56,
"width": 215,
}
scales["large"] = {
"download": download_url,
"height": 56,
"width": 215,
}
scales["teaser"] = {
"download": download_url,
"height": 56,
"width": 215,
}
self.assertEqual(
{
"filename": "image.png",
Expand Down