57ea0b2c8cb76378a0a09f236166e840cc2c6853
[yaffs-website] / web / core / modules / image / src / Plugin / ImageEffect / ScaleAndCropImageEffect.php
1 <?php
2
3 namespace Drupal\image\Plugin\ImageEffect;
4
5 use Drupal\Core\Image\ImageInterface;
6
7 /**
8  * Scales and crops an image resource.
9  *
10  * @ImageEffect(
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.")
14  * )
15  */
16 class ScaleAndCropImageEffect extends ResizeImageEffect {
17
18   /**
19    * {@inheritdoc}
20    */
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()]);
24       return FALSE;
25     }
26     return TRUE;
27   }
28
29 }