Version 1
[yaffs-website] / web / core / modules / system / src / Plugin / ImageToolkit / Operation / gd / Desaturate.php
1 <?php
2
3 namespace Drupal\system\Plugin\ImageToolkit\Operation\gd;
4
5 /**
6  * Defines GD2 Desaturate operation.
7  *
8  * @ImageToolkitOperation(
9  *   id = "gd_desaturate",
10  *   toolkit = "gd",
11  *   operation = "desaturate",
12  *   label = @Translation("Desaturate"),
13  *   description = @Translation("Converts an image to grayscale.")
14  * )
15  */
16 class Desaturate extends GDImageToolkitOperationBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   protected function arguments() {
22     // This operation does not use any parameters.
23     return [];
24   }
25
26   /**
27    * {@inheritdoc}
28    */
29   protected function execute(array $arguments) {
30     // PHP installations using non-bundled GD do not have imagefilter.
31     if (!function_exists('imagefilter')) {
32       $this->logger->notice("The image '@file' could not be desaturated because the imagefilter() function is not available in this PHP installation.", ['@file' => $this->getToolkit()->getSource()]);
33       return FALSE;
34     }
35
36     return imagefilter($this->getToolkit()->getResource(), IMG_FILTER_GRAYSCALE);
37   }
38
39 }