public function AspectSwitcherImageEffect::transformDimensions in Image Effects 8
Same name and namespace in other branches
- 8.3 src/Plugin/ImageEffect/AspectSwitcherImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\AspectSwitcherImageEffect::transformDimensions()
- 8.2 src/Plugin/ImageEffect/AspectSwitcherImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\AspectSwitcherImageEffect::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
- src/
Plugin/ ImageEffect/ AspectSwitcherImageEffect.php, line 168
Class
- AspectSwitcherImageEffect
- Choose image styles to apply based on source image orientation.
Namespace
Drupal\image_effects\Plugin\ImageEffectCode
public function transformDimensions(array &$dimensions, $uri) {
$style_name = $this
->getChildImageStyleToExecute($dimensions['width'], $dimensions['height']);
$style = $this
->failSafeGetImageStyle($style_name);
// No or missing child style to process.
if (!$style) {
return;
}
foreach ($style
->getEffects() as $effect) {
$effect
->transformDimensions($dimensions, $uri);
}
}