You are here

public function FocalPointEffectBase::getCrop in Focal Point 8

Get the cropped image.

Parameters

\Drupal\Core\Image\ImageInterface $image: The image resource whose crop is being requested.

Return value

\Drupal\crop\CropInterface The crop.

2 calls to FocalPointEffectBase::getCrop()
FocalPointCropImageEffect::applyEffect in src/Plugin/ImageEffect/FocalPointCropImageEffect.php
@codeCoverageIgnore
FocalPointScaleAndCropImageEffect::applyEffect in src/Plugin/ImageEffect/FocalPointScaleAndCropImageEffect.php
Applies an image effect to the image object.

File

src/FocalPointEffectBase.php, line 198

Class

FocalPointEffectBase
Provides a base class for image effects.

Namespace

Drupal\focal_point

Code

public function getCrop(ImageInterface $image) {
  $crop_type = $this->focalPointConfig
    ->get('crop_type');

  /** @var \Drupal\crop\CropInterface $crop */
  if ($crop = Crop::findCrop($image
    ->getSource(), $crop_type)) {

    // An existing crop has been found; set the size.
    $crop
      ->setSize($this->configuration['width'], $this->configuration['height']);
  }
  else {

    // No existing crop could be found; create a new one using the size.
    $crop = $this->cropStorage
      ->create([
      'type' => $crop_type,
      'x' => (int) round($this->originalImageSize['width'] / 2),
      'y' => (int) round($this->originalImageSize['height'] / 2),
      'width' => $this->configuration['width'],
      'height' => $this->configuration['height'],
    ]);
  }
  return $crop;
}