Mercurial > hg > isophonics-drupal-site
comparison core/modules/image/src/Plugin/ImageEffect/ScaleAndCropImageEffect.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
11 * id = "image_scale_and_crop", | 11 * id = "image_scale_and_crop", |
12 * label = @Translation("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.") | 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 * ) | 14 * ) |
15 */ | 15 */ |
16 class ScaleAndCropImageEffect extends ResizeImageEffect { | 16 class ScaleAndCropImageEffect extends CropImageEffect { |
17 | 17 |
18 /** | 18 /** |
19 * {@inheritdoc} | 19 * {@inheritdoc} |
20 */ | 20 */ |
21 public function applyEffect(ImageInterface $image) { | 21 public function applyEffect(ImageInterface $image) { |
22 if (!$image->scaleAndCrop($this->configuration['width'], $this->configuration['height'])) { | 22 $width = $this->configuration['width']; |
23 $height = $this->configuration['height']; | |
24 $scale = max($width / $image->getWidth(), $height / $image->getHeight()); | |
25 | |
26 list($x, $y) = explode('-', $this->configuration['anchor']); | |
27 $x = image_filter_keyword($x, $image->getWidth() * $scale, $width); | |
28 $y = image_filter_keyword($y, $image->getHeight() * $scale, $height); | |
29 | |
30 if (!$image->apply('scale_and_crop', ['x' => $x, 'y' => $y, 'width' => $width, 'height' => $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()]); | 31 $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; | 32 return FALSE; |
25 } | 33 } |
26 return TRUE; | 34 return TRUE; |
27 } | 35 } |
28 | 36 |
37 /** | |
38 * {@inheritdoc} | |
39 */ | |
40 public function getSummary() { | |
41 $summary = [ | |
42 '#theme' => 'image_scale_and_crop_summary', | |
43 '#data' => $this->configuration, | |
44 ]; | |
45 $summary += parent::getSummary(); | |
46 | |
47 return $summary; | |
48 } | |
49 | |
29 } | 50 } |