FocalPointScaleAndCropImageEffect.php in Focal Point 8
File
src/Plugin/ImageEffect/FocalPointScaleAndCropImageEffect.php
View source
<?php
namespace Drupal\focal_point\Plugin\ImageEffect;
use Drupal\focal_point\FocalPointEffectBase;
use Drupal\Core\Image\ImageInterface;
class FocalPointScaleAndCropImageEffect extends FocalPointEffectBase {
public function applyEffect(ImageInterface $image) {
parent::applyEffect($image);
$originalDimensions = $this
->getOriginalImageSize();
$resize_data = self::calculateResizeData($originalDimensions['width'], $originalDimensions['height'], $this->configuration['width'], $this->configuration['height']);
if (!$image
->resize($resize_data['width'], $resize_data['height'])) {
$this->logger
->error('Focal point scale and crop failed while resizing using the %toolkit toolkit on %path (%mimetype, %dimensions)', [
'%toolkit' => $image
->getToolkitId(),
'%path' => $image
->getSource(),
'%mimetype' => $image
->getMimeType(),
'%dimensions' => $image
->getWidth() . 'x' . $image
->getHeight(),
]);
return FALSE;
}
$crop = $this
->getCrop($image);
return $this
->applyCrop($image, $crop);
}
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'crop_type' => 'focal_point',
];
}
}