public function AutoAspectEffect::transformDimensions in Thunder 6.0.x
Same name and namespace in other branches
- 8.5 modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::transformDimensions()
- 8.2 modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::transformDimensions()
- 8.3 modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::transformDimensions()
- 8.4 modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::transformDimensions()
- 6.2.x modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::transformDimensions()
- 6.1.x modules/thunder_media/src/Plugin/ImageEffect/AutoAspectEffect.php \Drupal\thunder_media\Plugin\ImageEffect\AutoAspectEffect::transformDimensions()
Determines the dimensions of the styled image.
Parameters
array &$dimensions: Dimensions to be modified - an array with the following keys:
- width: the width in pixels, or NULL if unknown
- height: the height in pixels, or NULL if unknown
When either of the dimensions are NULL, the corresponding HTML attribute will be omitted when an image style using this image effect is used.
string $uri: Original image file URI. It is passed in to allow an effect to optionally use this information to retrieve additional image metadata to determine dimensions of the styled image. ImageEffectInterface::transformDimensions key objective is to calculate styled image dimensions without performing actual image operations, so be aware that performing IO on the URI may lead to decrease in performance.
Overrides ImageEffectBase::transformDimensions
File
- modules/
thunder_media/ src/ Plugin/ ImageEffect/ AutoAspectEffect.php, line 81
Class
- AutoAspectEffect
- Resizes an image resource.
Namespace
Drupal\thunder_media\Plugin\ImageEffectCode
public function transformDimensions(array &$dimensions, $uri) {
if (!isset($dimensions['width']) || !isset($dimensions['height'])) {
// We cannot know which preset would be executed and thus cannot know the
// resulting dimensions, unless both styles return the same dimensions:
$landscape_dimensions = $portrait_dimensions = $dimensions;
/** @var \Drupal\image\ImageStyleInterface $landscape_style */
$landscape_style = $this->entityTypeManager
->getStorage('image_style')
->load($this->configuration['landscape']);
$landscape_style
->transformDimensions($landscape_dimensions, $uri);
/** @var \Drupal\image\ImageStyleInterface $portrait_style */
$portrait_style = $this->entityTypeManager
->getStorage('image_style')
->load($this->configuration['portrait']);
$portrait_style
->transformDimensions($portrait_dimensions, $uri);
if ($landscape_dimensions == $portrait_dimensions) {
$dimensions = $landscape_dimensions;
}
else {
$dimensions['width'] = $dimensions['height'] = NULL;
}
}
else {
$ratio_adjustment = isset($this->configuration['ratio_adjustment']) ? floatval($this->configuration['ratio_adjustment']) : 1;
$aspect = $dimensions['width'] / $dimensions['height'];
$style_name = $aspect * $ratio_adjustment > 1 ? $this->configuration['landscape'] : $this->configuration['portrait'];
/** @var \Drupal\image\ImageStyleInterface $style */
$style = $this->entityTypeManager
->getStorage('image_style')
->load($style_name);
$style
->transformDimensions($dimensions, $uri);
}
}