You are here

public function FocalPointManager::relativeToAbsolute in Focal Point 8

Converts relative focal point coordinates to absolute coordinates.

Absolute coordinates are always specified in the context of the original image. Relative coordinates are percentages from the top left of the image so that using 50 for both x and y would mean to put the focal point in the center of the image.

Parameters

float $x: Relative X coordinate of the focal point. Maximum is 100.

float $y: Relative Y coordinate of the focal point. Maximum is 100.

int $width: Width of the original image.

int $height: Height of the original image.

Return value

array The absolute coordinates of the focal point on the original image. 'x' and 'y' are used for array keys and corresponding coordinates as values.

Overrides FocalPointManagerInterface::relativeToAbsolute

See also

absoluteToRelative

1 call to FocalPointManager::relativeToAbsolute()
FocalPointManager::saveCropEntity in src/FocalPointManager.php
Creates (or updates) a crop entity using relative focal point coordinates.

File

src/FocalPointManager.php, line 49

Class

FocalPointManager
Provides business logic related to focal point.

Namespace

Drupal\focal_point

Code

public function relativeToAbsolute($x, $y, $width, $height) {

  // Focal point JS provides relative location while crop entity
  // expects exact coordinate on the original image. Let's convert.
  return [
    'x' => (int) round($x / 100.0 * $width),
    'y' => (int) round($y / 100.0 * $height),
  ];
}