public function TextOverlayImageEffect::transformDimensions in Image Effects 8
Same name and namespace in other branches
- 8.3 src/Plugin/ImageEffect/TextOverlayImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\TextOverlayImageEffect::transformDimensions()
- 8.2 src/Plugin/ImageEffect/TextOverlayImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\TextOverlayImageEffect::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/ TextOverlayImageEffect.php, line 888
Class
- TextOverlayImageEffect
- Overlays text on the image, defining text font, size and positioning.
Namespace
Drupal\image_effects\Plugin\ImageEffectCode
public function transformDimensions(array &$dimensions, $uri) {
// Dimensions are potentially affected only if the effect is set to
// autoextend the background image in case of wrapper overflow. Also,
// current dimensions must be known.
if ($dimensions['width'] && $dimensions['height'] && $this->configuration['layout']['overflow_action'] == 'extend') {
$this->info['image_width'] = $dimensions['width'];
$this->info['image_height'] = $dimensions['height'];
// Get the text wrapper Image object.
if (!($wrapper = $this
->getTextWrapper())) {
return;
}
// Checks if resizing needed.
if ($this
->canvasResizeNeeded($wrapper)) {
$dimensions['width'] = $this->info['image_width'];
$dimensions['height'] = $this->info['image_height'];
}
}
}