diff --git a/docs/source/endpoints/content-types.md b/docs/source/endpoints/content-types.md index 06e36b4af..3e271046d 100644 --- a/docs/source/endpoints/content-types.md +++ b/docs/source/endpoints/content-types.md @@ -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 diff --git a/news/+scales.breaking b/news/+scales.breaking new file mode 100644 index 000000000..07644fafd --- /dev/null +++ b/news/+scales.breaking @@ -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 diff --git a/src/plone/restapi/imaging.py b/src/plone/restapi/imaging.py index 984fc88fa..394dfc3b1 100644 --- a/src/plone/restapi/imaging.py +++ b/src/plone/restapi/imaging.py @@ -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, diff --git a/src/plone/restapi/tests/http-examples/image.resp b/src/plone/restapi/tests/http-examples/image.resp index e459b587c..39f0fd4cc 100644 --- a/src/plone/restapi/tests/http-examples/image.resp +++ b/src/plone/restapi/tests/http-examples/image.resp @@ -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, @@ -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, diff --git a/src/plone/restapi/tests/http-examples/newsitem.resp b/src/plone/restapi/tests/http-examples/newsitem.resp index cab5656ca..6a2865070 100644 --- a/src/plone/restapi/tests/http-examples/newsitem.resp +++ b/src/plone/restapi/tests/http-examples/newsitem.resp @@ -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, @@ -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, diff --git a/src/plone/restapi/tests/test_dxfield_serializer.py b/src/plone/restapi/tests/test_dxfield_serializer.py index e718066f2..c9944440c 100644 --- a/src/plone/restapi/tests/test_dxfield_serializer.py +++ b/src/plone/restapi/tests/test_dxfield_serializer.py @@ -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, @@ -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, diff --git a/src/plone/restapi/tests/test_serializer.py b/src/plone/restapi/tests/test_serializer.py index 792b89313..95fc87d70 100644 --- a/src/plone/restapi/tests/test_serializer.py +++ b/src/plone/restapi/tests/test_serializer.py @@ -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",