Last active
August 28, 2024 06:59
-
-
Save rang501/94393cb899df79ebea605bbcf37535ad to your computer and use it in GitHub Desktop.
Drupal 8 get image dimensions by applying image style effects. This doesn't cause performance issue because the dimensions are calculated without creating the actual image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$image = \Drupal::service('image.factory')->get($file->getFileUri()); | |
$image_style = \Drupal\image\Entity\ImageStyle::load('gallery_large'); | |
// Set source image dimensions. | |
$dimensions = [ | |
'width' => $image->getWidth(), | |
'height' => $image->getHeight(), | |
]; | |
// After calling this, the $dimensions array will contain new dimensions. | |
$image_style->transformDimensions($dimensions, $file->getFileUri()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment