class Desaturate

Same name and namespace in other branches
  1. 11.x core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php \Drupal\system\Plugin\ImageToolkit\Operation\gd\Desaturate

Defines GD2 Desaturate operation.

Plugin annotation


@ImageToolkitOperation(
  id = "gd_desaturate",
  toolkit = "gd",
  operation = "desaturate",
  label = @Translation("Desaturate"),
  description = @Translation("Converts an image to grayscale.")
)

Hierarchy

Expanded class hierarchy of Desaturate

7 string references to 'Desaturate'
ImageEffectsTest::testDesaturateEffect in core/modules/image/tests/src/Kernel/ImageEffectsTest.php
Tests the 'image_desaturate' effect.
ImageTest::testDesaturate in core/tests/Drupal/Tests/Core/Image/ImageTest.php
Tests \Drupal\Core\Image\Image::desaturate().
ToolkitGdTest::providerTestImageFiles in core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php
Data provider for ::testManipulations().
ToolkitGdTest::testManipulations in core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php
Tests height, width and color for the corners for the final images.
ToolkitTestBase::assertToolkitOperationsCalled in core/tests/Drupal/FunctionalTests/Image/ToolkitTestBase.php
Tests that only allowed image toolkit operations are called.

... See full list

File

core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php, line 16

Namespace

Drupal\system\Plugin\ImageToolkit\Operation\gd
View source
class Desaturate extends GDImageToolkitOperationBase {
  
  /**
   * {@inheritdoc}
   */
  protected function arguments() {
    // This operation does not use any parameters.
    return [];
  }
  
  /**
   * {@inheritdoc}
   */
  protected function execute(array $arguments) {
    // PHP installations using non-bundled GD do not have imagefilter.
    if (!function_exists('imagefilter')) {
      $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(),
      ]);
      return FALSE;
    }
    return imagefilter($this->getToolkit()
      ->getResource(), IMG_FILTER_GRAYSCALE);
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.