You are here

private function FocusScaleCropImageEffect::getFocalPoint in Image Focus Crop 8

Method getFocalPoint.

Parameters

\Drupal\Core\Image\ImageInterface $image: Image.

Return value

array Return array.

1 call to FocusScaleCropImageEffect::getFocalPoint()
FocusScaleCropImageEffect::applyEffect in src/Plugin/ImageEffect/FocusScaleCropImageEffect.php
Applies an image effect to the image object.

File

src/Plugin/ImageEffect/FocusScaleCropImageEffect.php, line 66

Class

FocusScaleCropImageEffect
Crops with focus an image resource.

Namespace

Drupal\image_focus\Plugin\ImageEffect

Code

private function getFocalPoint(ImageInterface $image) {
  $extension = str_replace('jpg', 'jpeg', explode('/', $image
    ->getMimeType())[1]);
  $function = 'imagecreatefrom' . $extension;
  if (function_exists($function) && ($resource = $function($image
    ->getSource()))) {
    if ($this->configuration['face_detect']) {
      $config = \Drupal::configFactory()
        ->get('image_focus.settings');
      if ($config
        ->get('image_focus_face_detection_maxsize') * 1024 > $image
        ->getFileSize() && ($result = $this
        ->getFaceDetection($resource))) {
        return $result;
      }
    }
    if ($result = $this
      ->getImageEntropy($resource)) {
      return $result;
    }
  }
  return [
    $image
      ->getWidth() / 2,
    $image
      ->getHeight() / 2,
  ];
}