Mercurial > hg > isophonics-drupal-site
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php Wed Nov 29 16:09:58 2017 +0000 @@ -0,0 +1,29 @@ +<?php + +namespace Drupal\image\Plugin\ImageEffect; + +use Drupal\Core\Image\ImageInterface; + +/** + * Scales and crops an image resource. + * + * @ImageEffect( + * id = "image_scale_and_crop", + * label = @Translation("Scale and crop"), + * 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.") + * ) + */ +class ScaleAndCropImageEffect extends ResizeImageEffect { + + /** + * {@inheritdoc} + */ + public function applyEffect(ImageInterface $image) { + if (!$image->scaleAndCrop($this->configuration['width'], $this->configuration['height'])) { + $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()]); + return FALSE; + } + return TRUE; + } + +}