You are here

public function CropEffect::applyEffect in Crop API 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/ImageEffect/CropEffect.php \Drupal\crop\Plugin\ImageEffect\CropEffect::applyEffect()

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/CropEffect.php, line 105

Class

CropEffect
Crops an image resource.

Namespace

Drupal\crop\Plugin\ImageEffect

Code

public function applyEffect(ImageInterface $image) {
  if (empty($this->configuration['crop_type']) || !$this->typeStorage
    ->load($this->configuration['crop_type'])) {
    $this->logger
      ->error('Manual image crop failed due to misconfigured crop type on %path.', [
      '%path' => $image
        ->getSource(),
    ]);
    return FALSE;
  }
  $this
    ->getCrop($image);
  if (!$this->crop) {
    return FALSE;
  }
  $anchor = $this->crop
    ->anchor();
  $size = $this->crop
    ->size();
  if (!$image
    ->crop($anchor['x'], $anchor['y'], $size['width'], $size['height'])) {
    $this->logger
      ->error('Manual 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;
}