function ResponsiveImageBuilder::getImageDimensions
Determines the dimensions of an image.
Parameters
string $image_style_name: The name of the style to be used to alter the original image.
array $dimensions: An associative array containing:
- width: The width of the source image (if known).
- height: The height of the source image (if known).
string $uri: The URI of the image file.
Return value
array Dimensions to be modified - an array with components width and height, in pixels.
File
-
core/
modules/ responsive_image/ src/ ResponsiveImageBuilder.php, line 274
Class
- ResponsiveImageBuilder
- Provides methods related to building responsive image source attributes.
Namespace
Drupal\responsive_imageCode
public function getImageDimensions(string $image_style_name, array $dimensions, string $uri) : array {
// Determine the dimensions of the styled image.
if ($image_style_name == ResponsiveImageStyleInterface::EMPTY_IMAGE) {
$dimensions = [
'width' => 1,
'height' => 1,
];
}
elseif ($entity = $this->entityTypeManager
->getStorage('image_style')
->load($image_style_name)) {
assert($entity instanceof ImageStyle);
$entity->transformDimensions($dimensions, $uri);
}
return $dimensions;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.