public function FocalPointEffectBase::applyCrop in Focal Point 8
Applies the crop effect to an image.
Parameters
\Drupal\Core\Image\ImageInterface $image: The image resource to crop.
\Drupal\crop\CropInterface $crop: A crop object containing the relevant crop information.
Return value
bool TRUE if the image is successfully cropped, otherwise FALSE.
2 calls to FocalPointEffectBase::applyCrop()
- 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 168  
Class
- FocalPointEffectBase
 - Provides a base class for image effects.
 
Namespace
Drupal\focal_pointCode
public function applyCrop(ImageInterface $image, CropInterface $crop) {
  // Get the top-left anchor position of the crop area.
  $anchor = $this
    ->getAnchor($image, $crop);
  if (!$image
    ->crop($anchor['x'], $anchor['y'], $this->configuration['width'], $this->configuration['height'])) {
    $this->logger
      ->error('Focal point scale and crop failed while scaling and cropping using the %toolkit toolkit on %path (%mimetype, %dimensions, anchor: %anchor)', [
      '%toolkit' => $image
        ->getToolkitId(),
      '%path' => $image
        ->getSource(),
      '%mimetype' => $image
        ->getMimeType(),
      '%dimensions' => $image
        ->getWidth() . 'x' . $image
        ->getHeight(),
      '%anchor' => $anchor,
    ]);
    return FALSE;
  }
  return TRUE;
}