You are here

public function AutomatedCropEffect::transformDimensions in Automated Crop 8

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/AutomatedCropEffect.php, line 235

Class

AutomatedCropEffect
Provide an Automatic crop tools.

Namespace

Drupal\automated_crop\Plugin\ImageEffect

Code

public function transformDimensions(array &$dimensions, $uri) {

  /** @var \Drupal\Core\Image\Image $image */
  $image = $this->imageFactory
    ->get($uri);
  $sizes = $this
    ->getAutomatedCrop($image)
    ->size();

  // The new image will have the exact dimensions defined by effect.
  $dimensions['width'] = $sizes['width'];
  $dimensions['height'] = $sizes['height'];
}