You are here

public function AutomatedCropEffect::applyEffect in Automated Crop 8

Applies an image effect to the image object.

Parameters

\Drupal\Core\Image\ImageInterface $image: An image file object.

Return value

bool TRUE on success. FALSE if unable to perform the image effect on the image.

Overrides ImageEffectInterface::applyEffect

File

src/Plugin/ImageEffect/AutomatedCropEffect.php, line 73

Class

AutomatedCropEffect
Provide an Automatic crop tools.

Namespace

Drupal\automated_crop\Plugin\ImageEffect

Code

public function applyEffect(ImageInterface $image) {

  /** @var \Drupal\automated_crop\AutomatedCropInterface $crop */
  if ($crop = $this
    ->getAutomatedCrop($image)) {
    $anchor = $crop
      ->anchor();
    $size = $crop
      ->size();
    if (!$image
      ->crop($anchor['x'], $anchor['y'], $size['width'], $size['height'])) {
      $this->logger
        ->error('Automated image crop failed using the %toolkit toolkit on %path (%mimetype, %width x %height)', [
        '%toolkit' => $image
          ->getToolkitId(),
        '%path' => $image
          ->getSource(),
        '%mimetype' => $image
          ->getMimeType(),
        '%width' => $image
          ->getWidth(),
        '%height' => $image
          ->getHeight(),
      ]);
      return FALSE;
    }
  }
  return TRUE;
}