You are here

protected function FocalPointEffectBase::getOriginalFocalPoint in Focal Point 8

Returns the focal point value (in pixels) relative to the original image.

Parameters

\Drupal\crop\CropInterface $crop: The crop object used to define the crop.

\Drupal\focal_point\FocalPointManager $focal_point_manager: The focal point manager.

Return value

array An array with the keys 'x' and 'y'. Values are in pixels.

1 call to FocalPointEffectBase::getOriginalFocalPoint()
FocalPointEffectBase::getAnchor in src/FocalPointEffectBase.php
Get the top-left anchor position of the crop area.

File

src/FocalPointEffectBase.php, line 370

Class

FocalPointEffectBase
Provides a base class for image effects.

Namespace

Drupal\focal_point

Code

protected function getOriginalFocalPoint(CropInterface $crop, FocalPointManager $focal_point_manager) {
  $focal_point = $crop
    ->position();

  // Check if we are generating a preview image. If so get the focal point
  // from the query parameter, otherwise use the crop position.
  $preview_value = $this
    ->getPreviewValue();
  if (!is_null($preview_value)) {

    // @todo: should we check that preview_value is valid here? If it's invalid it gets converted to 0,0.
    $original_image_size = $this
      ->getOriginalImageSize();
    list($x, $y) = explode('x', $preview_value);
    $focal_point = $focal_point_manager
      ->relativeToAbsolute($x, $y, $original_image_size['width'], $original_image_size['height']);
  }
  return $focal_point;
}