plone/plone.namedfile

Index all image scales, no matter the actual size

erral opened this issue · 4 comments

erral commented

I find inconsistent that we index in the catalog metadata just some scales for an image and then requesting to the plone.restapi endpoint receiving all URLs for all configured image scales.

For instance:

This is the restapi response:

https://2023.ploneconf.org/++api++/accomodation/1111_fotpe1_fachada.jpg

"image": {
    "content-type": "image/jpeg", 
    "download": "https://2023.ploneconf.org/accomodation/1111_fotpe1_fachada.jpg/@@images/image-519-d8e3ae51320189e0d48d5032325bbab6.jpeg", 
    "filename": "1111_fotpe1_fachada.jpg", 
    "height": 600, 
    "scales": {
      "great": {
        "download": "https://2023.ploneconf.org/accomodation/1111_fotpe1_fachada.jpg/@@images/image-1200-0cb50e0c06f8f905ba111647b2512c29.jpeg", 
        "height": 600, 
        "width": 519
      }, 
      "huge": {
        "download": "https://2023.ploneconf.org/accomodation/1111_fotpe1_fachada.jpg/@@images/image-1600-f6c90960c0303e65aa57fbeb576533c0.jpeg", 
        "height": 600, 
        "width": 519
      }, 
      "icon": {
        "download": "https://2023.ploneconf.org/accomodation/1111_fotpe1_fachada.jpg/@@images/image-32-2e770277beaee989c15c5f64f550fad9.jpeg", 
        "height": 32, 
        "width": 28
      }, 
      "large": {
        "download": "https://2023.ploneconf.org/accomodation/1111_fotpe1_fachada.jpg/@@images/image-800-a56e1fb18d700a641285a81c30caca1e.jpeg", 
        "height": 600, 
        "width": 519
      }, 
      "larger": {
        "download": "https://2023.ploneconf.org/accomodation/1111_fotpe1_fachada.jpg/@@images/image-1000-71d3c8f46dbf7bd654a7d2aa0128fcfc.jpeg", 
        "height": 600, 
        "width": 519
      }, 
      "mini": {
        "download": "https://2023.ploneconf.org/accomodation/1111_fotpe1_fachada.jpg/@@images/image-200-f878c801f90e108d8236b98261b3262d.jpeg", 
        "height": 231, 
        "width": 200
      }, 
      "preview": {
        "download": "https://2023.ploneconf.org/accomodation/1111_fotpe1_fachada.jpg/@@images/image-400-c14554d35bfd7d8672bdca38d85c7ec8.jpeg", 
        "height": 462, 
        "width": 400
      }, 
      "teaser": {
        "download": "https://2023.ploneconf.org/accomodation/1111_fotpe1_fachada.jpg/@@images/image-600-102e1380a97eefef487b31a2e2dd48de.jpeg", 
        "height": 600, 
        "width": 519
      }, 
      "thumb": {
        "download": "https://2023.ploneconf.org/accomodation/1111_fotpe1_fachada.jpg/@@images/image-128-0cc82a203ab39309932391cc0e7945cd.jpeg", 
        "height": 128, 
        "width": 111
      }, 
      "tile": {
        "download": "https://2023.ploneconf.org/accomodation/1111_fotpe1_fachada.jpg/@@images/image-64-1cee74d235d28d0da7f4789e71b2f29d.jpeg", 
        "height": 64, 
        "width": 56
      }
    }, 
    "size": 273789, 
    "width": 519
  }, 

But this is the restapi response when searching for the same item:

https://2023.ploneconf.org/++api++/@search?path.query=accomodation/1111_fotpe1_fachada.jpg

"image_scales": {
        "image": [
          {
            "content-type": "image/jpeg", 
            "download": "@@images/image-519-83d59392a9853e1c02d49572d7f3d9d4.jpeg", 
            "filename": "1111_fotpe1_fachada.jpg", 
            "height": 600, 
            "scales": {
              "icon": {
                "download": "@@images/image-32-4738fb987e65577087fd99b82e06ee18.jpeg", 
                "height": 32, 
                "width": 28
              }, 
              "mini": {
                "download": "@@images/image-200-c46d75543ee91db00d59f7dc25eee6a5.jpeg", 
                "height": 231, 
                "width": 200
              }, 
              "preview": {
                "download": "@@images/image-400-ec03ddc4d1cbbce5b468673412c881b2.jpeg", 
                "height": 462, 
                "width": 400
              }, 
              "thumb": {
                "download": "@@images/image-128-70c2da4ad7ad1d535389d84a456453ee.jpeg", 
                "height": 128, 
                "width": 111
              }, 
              "tile": {
                "download": "@@images/image-64-b7e543169ac9fc5c23180ebba23ddb28.jpeg", 
                "height": 64, 
                "width": 56
              }
            }, 
            "size": 273789, 
            "width": 519
          }
        ]
      }, 

I would find much more consistent to have all of them indexed in the catalog too, otherwise the REST API user (in our case when building a Volto site), needs to do a lot of checks like "if this item hasn't the scale named large use the one named preview and if not mini, etc.)

Tough one.

The catalog info is mainly there for when you display images in listings. I don't like to have info in there for scales that are larger than what you actually get. It is not much use listing ten scales in a source set when the biggest five of them are completely the same.

Fair point though that you would like to avoid complicating a template with logic to try to show the highest available scale.

Still, wouldn't it be okay to say in a template: use the large scale, and if this is not available you fall back to the original?

erral commented

Fair point though that you would like to avoid complicating a template with logic to try to show the highest available scale.

Still, wouldn't it be okay to say in a template: use the large scale, and if this is not available you fall back to the original?

It depends from template to template.

erral commented

I mean, it could work, but what I wanted to state is the difference between the image scales information we are saving (and exposing through the REST API) in the catalog metadata and what we are exposing in the content itself.

Any opinions on this @plone/restapi-team?

My opinion: It's a bug that the serialization of an image field includes scale sizes larger than the original image. Probably this serializer needs to be updated to get the scales the same way as the catalog does (using an IImageScalesFieldAdapter).