annotate core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php @ 0:c75dbcec494b
Initial commit from drush-created site
author |
Chris Cannam |
date |
Thu, 05 Jul 2018 14:24:15 +0000 |
parents |
|
children |
a9cd425dd02b |
rev |
line source |
Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\image\Plugin\ImageEffect;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Image\ImageInterface;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Scales and crops an image resource.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @ImageEffect(
|
Chris@0
|
11 * id = "image_scale_and_crop",
|
Chris@0
|
12 * label = @Translation("Scale and crop"),
|
Chris@0
|
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.")
|
Chris@0
|
14 * )
|
Chris@0
|
15 */
|
Chris@0
|
16 class ScaleAndCropImageEffect extends ResizeImageEffect {
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * {@inheritdoc}
|
Chris@0
|
20 */
|
Chris@0
|
21 public function applyEffect(ImageInterface $image) {
|
Chris@0
|
22 if (!$image->scaleAndCrop($this->configuration['width'], $this->configuration['height'])) {
|
Chris@0
|
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()]);
|
Chris@0
|
24 return FALSE;
|
Chris@0
|
25 }
|
Chris@0
|
26 return TRUE;
|
Chris@0
|
27 }
|
Chris@0
|
28
|
Chris@0
|
29 }
|