Error in calculateScaleDimensions breaks pages using that image

Created on 10 March 2025, about 2 months ago

Problem/Motivation

I updated an image in the Dam and then synced with Drupal. On a page using that media, I'm getting WSOD and this error in the logs:
TypeError: Drupal\acquia_dam\EmbedCodeUrlBuilder::calculateScaleDimensions(): Argument #1 ($original_dimension) must be of type int, null given, called in /var/www/html/docroot/modules/contrib/acquia_dam/src/EmbedCodeUrlBuilder.php on line 146 in Drupal\acquia_dam\EmbedCodeUrlBuilder::calculateScaleDimensions() (line 175 of /var/www/html/docroot/modules/contrib/acquia_dam/src/EmbedCodeUrlBuilder.php).

Steps to reproduce

Working on steps to reproduce.

I'm using version 1.1.0-beta5 on Drupal 10.4.3, php 8.3.15.

I see that there were changes to this code in https://www.drupal.org/project/acquia_dam/issues/3340734 🐛 Scale effect is setting bad parameters, does not return image Active , but I'm not sure yet if that's related.

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

🇺🇸United States capysara

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @capysara
  • 🇺🇸United States capysara

    I tried the Sync Metadata from /admin/content/media again, and this time it seemed to fix it. Is it possible that the first time I tried it there wasn't enough time between updating in Dam and trying to sync in Drupal? If that's the case, is there any way to make it fail more gracefully?

  • 🇨🇦Canada ibullock London, ON

    Also experienced this issue today on a production site. Thanks @capysara for the workaround!

  • 🇮🇳India vipin.mittal18 Greater Noida

    Hello @capysara, Could you please outline the exact steps to reproduce the issue?

  • 🇺🇸United States dan612 Portland, Maine

    I think this boils down to the image dimensions being missing in the DAM for the source image and an image style that needs to scale is being used. I was experiencing this issue and worked through the stack trace:

    "Drupal\acquia_dam\EmbedCodeUrlBuilder::calculateScaleDimensions(): Argument #1 ($original_dimension) must be of type int, null given"

    This is being called from Drupal\acquia_dam\EmbedCodeUrlBuilder::mapImageEffects. There is a switch statement to handle various different image effects in mapImageEffects. I am using scale and crop on the image style which is failing, so the following code is being run:

            case 'image_scale_and_crop':
              $values['crop'] = 'yes';
              $values['k'] = $anchor_mapping[$effect['data']['anchor']] ?? 'c';
              $values['w'] = self::calculateScaleDimensions(
                $image_properties['width'],
                self::getDimensionValue($effect['data']['width']),
                TRUE
              );
              $values['h'] = self::calculateScaleDimensions(
                $image_properties['height'],
                self::getDimensionValue($effect['data']['height']),
                TRUE
              );
              break;
    

    The args being passed to calculateScaleDimensions are null, at least for these:

    $image_properties['width'],
    $image_properties['height'],

    $image_properties are passed into the mapImageEffects method, so that means $image_properties value is created in a different location. That location is Drupal\acquia_dam\StreamWrapper\AcquiaDamStreamWrapper->loadAsset. When the following line is run:
    $asset_data = $this->getDamClient()->getAsset($this->assetId, $this->versionId);

    They are null:

    When i look in the DAM, these values are missing in the file data:

    I am not sure what would cause those values to be missing in the DAM, or the best way to update them for that matter.

    In terms of failing more gracefully...im not really sure best approach because if it cannot properly apply the image style then it seems like it should hard fail - if we default to "original image" or something if the dimensions are not found, that could be misleading to users who think perhaps the issue is with their entity type display configurations.

  • 🇮🇳India vishalkhode

    I've to verified and not seeing any error with 1.1.x. Looks like this is already fixed & merged as part of 🐛 TypeError on EmbedCodeUrlBuilder on new revision update for an existing asset/image on Acquia DAM Active . Hence, closing.

Production build 0.71.5 2024