function ToolkitGdTest::testIncorrectIccpSrgbProfile

Tests that GD doesn't trigger warnings for iCCP sRGB profiles.

If image is saved with 'sRGB IEC61966-2.1' sRGB profile, GD will trigger a warning about an incorrect sRGB profile'.

@dataProvider pngImageProvider

File

core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php, line 546

Class

ToolkitGdTest
Tests for the GD image toolkit.

Namespace

Drupal\KernelTests\Core\Image

Code

public function testIncorrectIccpSrgbProfile(string $image_uri) : void {
  $warning_detected = FALSE;
  // @see https://github.com/sebastianbergmann/phpunit/issues/5062
  $error_handler = static function () use (&$warning_detected) : void {
    $warning_detected = TRUE;
  };
  // $error_level is intentionally set to 0. It's required for PHP '@'
  // suppression not to trigger Drupal error handler. In that case native
  // PHP handler will be called and Drupal's will serve like a notification.
  set_error_handler($error_handler, 0);
  $image_factory = $this->container
    ->get('image.factory');
  \assert($image_factory instanceof ImageFactory);
  $image = $image_factory->get($image_uri, 'gd');
  // We need to do any image manipulation to trigger GD profile loading.
  $image->resize('100', '100');
  self::assertFalse($warning_detected);
  restore_error_handler();
}

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