3 namespace Drupal\system\Plugin\ImageToolkit\Operation\gd;
6 * Defines GD2 Desaturate operation.
8 * @ImageToolkitOperation(
9 * id = "gd_desaturate",
11 * operation = "desaturate",
12 * label = @Translation("Desaturate"),
13 * description = @Translation("Converts an image to grayscale.")
16 class Desaturate extends GDImageToolkitOperationBase {
21 protected function arguments() {
22 // This operation does not use any parameters.
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()]);
36 return imagefilter($this->getToolkit()->getResource(), IMG_FILTER_GRAYSCALE);