You are here

protected function AutomatedCropDefault::automatedCropBoxCalculation in Automated Crop 8

Calculate size automatically based on origin image width.

This method admit you want to crop the height of your image in another, ratio with respect of original image homothety. If you not define any, ratio in plugin configuration, nothing happen. If you define a new ratio, your image will conserve his original width but the height will, calculated to respect plugin ratio given.

This method contains a system that avoids exceeding, the maximum sizes of the cropBox. Pay attention with the, configurations of max width/height.

1 call to AutomatedCropDefault::automatedCropBoxCalculation()
AutomatedCropDefault::calculateCropBoxSize in src/Plugin/AutomatedCrop/AutomatedCropDefault.php
Calculation of the dimensions of the crop area.

File

src/Plugin/AutomatedCrop/AutomatedCropDefault.php, line 67

Class

AutomatedCropDefault
Class Generic routing entity mapper.

Namespace

Drupal\automated_crop\Plugin\AutomatedCrop

Code

protected function automatedCropBoxCalculation() {
  $delta = $this
    ->getDelta();
  $width = $this->originalImageSizes['width'];
  $height = round($this->cropBox['max_height'] * $delta);
  if (!empty($this->cropBox['max_height']) && $height > $this->cropBox['max_height']) {
    $height = $this->cropBox['max_height'];
    $width = round($height * $delta);
  }
  if (!empty($this->cropBox['max_width']) && $width > $this->cropBox['max_width']) {
    $width = $this->cropBox['max_width'];
    $height = round($width * $delta);
  }
  $this->cropBox['width'] = $width;
  $this->cropBox['height'] = $height;
}