protected function FocalPointEffectBase::calculateAnchor in Focal Point 8
Calculate the top left coordinates of crop rectangle.
This is based on Crop's anchor function with additional logic to ensure that crop area doesn't fall outside of the original image. Note that the image modules crop effect expects the top left coordinate of the crop rectangle.
Parameters
array $focal_point: The focal point value.
\Drupal\Core\Image\ImageInterface $image: The original image to be cropped.
\Drupal\crop\CropInterface $crop: The crop object used to define the crop.
Return value
array An array with the keys 'x' and 'y'.
1 call to FocalPointEffectBase::calculateAnchor()
- FocalPointEffectBase::getAnchor in src/
FocalPointEffectBase.php - Get the top-left anchor position of the crop area.
File
- src/
FocalPointEffectBase.php, line 304
Class
- FocalPointEffectBase
- Provides a base class for image effects.
Namespace
Drupal\focal_pointCode
protected function calculateAnchor(array $focal_point, ImageInterface $image, CropInterface $crop) {
$crop_size = $crop
->size();
// The anchor must be the top-left coordinate of the crop area but the focal
// point is expressed as the center coordinates of the crop area.
$anchor = [
'x' => (int) ($focal_point['x'] - $crop_size['width'] / 2),
'y' => (int) ($focal_point['y'] - $crop_size['height'] / 2),
];
$anchor = $this
->constrainCropArea($anchor, $image, $crop);
return $anchor;
}