comparison core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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 }