3 namespace Drupal\image\Plugin\ImageEffect;
5 use Drupal\Core\Image\ImageInterface;
8 * Scales and crops an image resource.
11 * id = "image_scale_and_crop",
12 * label = @Translation("Scale and crop"),
13 * description = @Translation("Scale and crop will maintain the aspect-ratio of the original image, then crop the larger dimension. This is most useful for creating perfectly square thumbnails without stretching the image.")
16 class ScaleAndCropImageEffect extends ResizeImageEffect {
21 public function applyEffect(ImageInterface $image) {
22 if (!$image->scaleAndCrop($this->configuration['width'], $this->configuration['height'])) {
23 $this->logger->error('Image scale and crop failed using the %toolkit toolkit on %path (%mimetype, %dimensions)', ['%toolkit' => $image->getToolkitId(), '%path' => $image->getSource(), '%mimetype' => $image->getMimeType(), '%dimensions' => $image->getWidth() . 'x' . $image->getHeight()]);