protected function FocalPointEffectBase::transformFocalPoint in Focal Point 8
Returns the focal point value (in pixels) relative to the provided image.
Parameters
\Drupal\Core\Image\ImageInterface $image: Image object that the focal point must be applied to.
array $original_focal_point: An array with keys 'x' and 'y' which represent the focal point in pixels relative to the original image.
Return value
array An array with the keys 'x' and 'y'. Values are in pixels.
1 call to FocalPointEffectBase::transformFocalPoint()
- FocalPointEffectBase::getAnchor in src/
FocalPointEffectBase.php - Get the top-left anchor position of the crop area.
File
- src/
FocalPointEffectBase.php, line 398
Class
- FocalPointEffectBase
- Provides a base class for image effects.
Namespace
Drupal\focal_pointCode
protected function transformFocalPoint(ImageInterface $image, array $original_focal_point) {
$image_size = [
'width' => $image
->getWidth(),
'height' => $image
->getHeight(),
];
$original_image_size = $this
->getOriginalImageSize();
$relative_focal_point = [
'x' => (int) round($original_focal_point['x'] / $original_image_size['width'] * $image_size['width']),
'y' => (int) round($original_focal_point['y'] / $original_image_size['height'] * $image_size['height']),
];
return $relative_focal_point;
}