You are here

public function AutomatedCropDefault::calculateCropBoxSize in Automated Crop 8

Calculation of the dimensions of the crop area.

This method allow you to define a specific logic to calculate, the sizes of crop area.

Return value

self AutomatedCrop plugin with cropBox set.

Overrides AbstractAutomatedCrop::calculateCropBoxSize

See also

\Drupal\automated_crop\Plugin\AutomatedCrop\AutomatedCropDefault

File

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

Class

AutomatedCropDefault
Class Generic routing entity mapper.

Namespace

Drupal\automated_crop\Plugin\AutomatedCrop

Code

public function calculateCropBoxSize() {
  if (!$this
    ->hasSizes() && !$this
    ->hasHardSizes()) {
    $this
      ->automatedCropBoxCalculation();
  }
  if ('width' === $this
    ->findUnknownValue()) {
    $value = !empty($this->cropBox['width']) ? $this->cropBox['width'] : $this->cropBox['max_width'];
    $this
      ->setCropBoxSize($this
      ->calculateUnknownValue($value), $this->cropBox['height']);
  }
  if ('height' === $this
    ->findUnknownValue()) {
    $value = !empty($this->cropBox['height']) ? $this->cropBox['height'] : $this->cropBox['max_height'];
    $this
      ->setCropBoxSize($this->cropBox['width'], $this
      ->calculateUnknownValue($value));
  }

  // Initialize auto crop area & unsure we can't exceed original image sizes.
  $width = min(max($this->cropBox['width'], $this->cropBox['min_width']), $this->cropBox['max_width']);
  $height = min(max($this->cropBox['height'], $this->cropBox['min_height']), $this->cropBox['max_height']);
  $this
    ->setCropBoxSize($width, $height);
  return $this;
}