X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fimage%2Fsrc%2FPlugin%2FImageEffect%2FScaleAndCropImageEffect.php;fp=web%2Fcore%2Fmodules%2Fimage%2Fsrc%2FPlugin%2FImageEffect%2FScaleAndCropImageEffect.php;h=5f06674dd6e27aa7d4ee1c3e8079db9d390d8666;hp=57ea0b2c8cb76378a0a09f236166e840cc2c6853;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hpb=74df008bdbb3a11eeea356744f39b802369bda3c diff --git a/web/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php b/web/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php index 57ea0b2c8..5f06674dd 100644 --- a/web/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php +++ b/web/core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php @@ -13,17 +13,38 @@ use Drupal\Core\Image\ImageInterface; * 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 { +class ScaleAndCropImageEffect extends CropImageEffect { /** * {@inheritdoc} */ public function applyEffect(ImageInterface $image) { - if (!$image->scaleAndCrop($this->configuration['width'], $this->configuration['height'])) { + $width = $this->configuration['width']; + $height = $this->configuration['height']; + $scale = max($width / $image->getWidth(), $height / $image->getHeight()); + + list($x, $y) = explode('-', $this->configuration['anchor']); + $x = image_filter_keyword($x, $image->getWidth() * $scale, $width); + $y = image_filter_keyword($y, $image->getHeight() * $scale, $height); + + if (!$image->apply('scale_and_crop', ['x' => $x, 'y' => $y, 'width' => $width, 'height' => $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; } + /** + * {@inheritdoc} + */ + public function getSummary() { + $summary = [ + '#theme' => 'image_scale_and_crop_summary', + '#data' => $this->configuration, + ]; + $summary += parent::getSummary(); + + return $summary; + } + }