We have a recurring need to now the actual size of the derivative before loading it. This module currently only provides the derivative image URL in its output.
I suggest that we add a width and a height properties to the meta structure of each derivative, in the same way it's done in the meta of the Image field data.

Comments

garphy created an issue. See original summary.

garphy’s picture

Status: Active » Needs review
StatusFileSize
new765 bytes

Here's a first attempt to add width & height.

garphy’s picture

StatusFileSize
new2.04 KB
new1.29 KB

This new patch adds derivative dimensions (width & height) to file entity links built by LinkCollectionNormalizer.

Kojo Unsui’s picture

Very useful patch !

Applied smoothly on Drupal 9.1.7 with PHP 7.4.13.

Here is a related snippet of JSON:API Resource after applying #3 :

 "imageDerivatives": {
              "links": {
                "large": {
                  "href": "https://backend.ddev.site:8002/sites/default/files/styles/large/public/2021-04/Kiwi_Male_flower.jpg?itok=4pwDnilr",
                  "meta": {
                    "rel": [
                      "drupal://jsonapi/extensions/consumer_image_styles/links/relation-types/#derivative"
                    ],
                    "width": 480,
                    "height": 360
                  }
                },

So far so good. Thanks !

Status: Needs review » Needs work

The last submitted patch, 3: consumer_image_styles-derivative_dimensions-3069385-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

bradjones1’s picture

I think this will also require an update to the enhancer's schema - see #3202870: Fix JSON schema for image style enhancer

bradjones1’s picture

I am overriding various classes in the image style generation pipeline so not using this patch directly, but I think the approach is correct. I will update the schema issue, referenced above.

rrrob’s picture

Version: 8.x-3.x-dev » 4.x-dev

This patch works great. Switching version to 4.x.

rrrob’s picture

Here's a reroll to work on 4.x.

rrrob’s picture

StatusFileSize
new2.04 KB

Tests for 4.x need to be enabled.

e0ipso’s picture

Status: Needs work » Needs review
e0ipso’s picture

StatusFileSize
new3.37 KB
new2.95 KB

Added some minor tweaks.

e0ipso’s picture

Mind that in the final version the dimensions are now nested into the 'meta', that was the only option allowed by https://jsonapi.org/format/1.1/#document-links-link-object

I wish LinkCollection was more usable so we could leverage it and the serialization component.

  • e0ipso committed c23de56 on 4.x authored by garphy
    Issue #3069385 by garphy, rrrob, e0ipso, bradjones1, Kojo Unsui: Provide...
e0ipso’s picture

Status: Needs review » Fixed
bradjones1’s picture

osopolar’s picture

Please see #3240536: Missing image causes type error. May we undo these changes for now?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jsacksick’s picture

Note that this introduced a serious "bug" described in #3252023: Very slow JSON:API responses when images are stored on AWS bucket.

tjh’s picture

With this change effectively reverted due to the "bug" described in https://www.drupal.org/project/consumer_image_styles/issues/3252023, what would be a more correct way to include the values of the derived image dimensions?