You are here

public function SmartCropImageEffect::applyEffect in Image Effects 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/ImageEffect/SmartCropImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\SmartCropImageEffect::applyEffect()
  2. 8.2 src/Plugin/ImageEffect/SmartCropImageEffect.php \Drupal\image_effects\Plugin\ImageEffect\SmartCropImageEffect::applyEffect()

Applies an image effect to the image object.

Parameters

\Drupal\Core\Image\ImageInterface $image: An image file object.

Return value

bool TRUE on success. FALSE if unable to perform the image effect on the image.

Overrides ImageEffectInterface::applyEffect

File

src/Plugin/ImageEffect/SmartCropImageEffect.php, line 159

Class

SmartCropImageEffect
Crop an image preserving the portion with the most entropy.

Namespace

Drupal\image_effects\Plugin\ImageEffect

Code

public function applyEffect(ImageInterface $image) {
  $dimensions = ImageUtility::resizeDimensions($image
    ->getWidth(), $image
    ->getHeight(), $this->configuration['width'], $this->configuration['height'], $this->configuration['square']);
  return $image
    ->apply('smart_crop', [
    'width' => min($dimensions['width'], $image
      ->getWidth()),
    'height' => min($dimensions['height'], $image
      ->getHeight()),
    'algorithm' => $this->configuration['algorithm'],
    'simulate' => $this->configuration['simulate'],
  ]);
}