You are here

public function FocalPointManager::saveCropEntity in Focal Point 8

Creates (or updates) a crop entity using relative focal point coordinates.

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.

\Drupal\crop\CropInterface $crop: Crop entity for the given file.

Return value

\Drupal\crop\CropInterface Saved crop entity.

Overrides FocalPointManagerInterface::saveCropEntity

File

src/FocalPointManager.php, line 94

Class

FocalPointManager
Provides business logic related to focal point.

Namespace

Drupal\focal_point

Code

public function saveCropEntity($x, $y, $width, $height, CropInterface $crop) {
  $absolute = $this
    ->relativeToAbsolute($x, $y, $width, $height);
  $anchor = $crop
    ->anchor();
  if ($anchor['x'] != $absolute['x'] || $anchor['y'] != $absolute['y']) {
    $crop
      ->setPosition($absolute['x'], $absolute['y']);
    $crop
      ->save();
  }
  return $crop;
}