function GdToolkitImageManipulationTestBase::providerOperationTestCases
Data provider for ::testManipulations().
2 calls to GdToolkitImageManipulationTestBase::providerOperationTestCases()
- GdToolkitGifImageManipulationTest::providerOperationTestCases in core/
tests/ Drupal/ KernelTests/ Core/ Image/ GdToolkitGifImageManipulationTest.php - Data provider for ::testManipulations().
- GdToolkitNoTransparencyGifImageManipulationTest::providerOperationTestCases in core/
tests/ Drupal/ KernelTests/ Core/ Image/ GdToolkitNoTransparencyGifImageManipulationTest.php - Data provider for ::testManipulations().
2 methods override GdToolkitImageManipulationTestBase::providerOperationTestCases()
- GdToolkitGifImageManipulationTest::providerOperationTestCases in core/
tests/ Drupal/ KernelTests/ Core/ Image/ GdToolkitGifImageManipulationTest.php - Data provider for ::testManipulations().
- GdToolkitNoTransparencyGifImageManipulationTest::providerOperationTestCases in core/
tests/ Drupal/ KernelTests/ Core/ Image/ GdToolkitNoTransparencyGifImageManipulationTest.php - Data provider for ::testManipulations().
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Image/ GdToolkitImageManipulationTestBase.php, line 109
Class
- GdToolkitImageManipulationTestBase
- GD image toolkit image manipulation test base class.
Namespace
Drupal\KernelTests\Core\ImageCode
public static function providerOperationTestCases() : array {
// Typically the corner colors will be unchanged. These colors are in the
// order of top-left, top-right, bottom-right, bottom-left.
$default_corners = [
static::RED,
static::GREEN,
static::BLUE,
static::TRANSPARENT,
];
// Setup a list of tests to perform on each type.
$test_cases = [
'resize' => [
'operation' => 'resize',
'arguments' => [
'width' => 20,
'height' => 10,
],
'width' => 20,
'height' => 10,
'corners' => $default_corners,
],
'scale_x' => [
'operation' => 'scale',
'arguments' => [
'width' => 20,
],
'width' => 20,
'height' => 10,
'corners' => $default_corners,
],
'scale_y' => [
'operation' => 'scale',
'arguments' => [
'height' => 10,
],
'width' => 20,
'height' => 10,
'corners' => $default_corners,
],
'upscale_x' => [
'operation' => 'scale',
'arguments' => [
'width' => 80,
'upscale' => TRUE,
],
'width' => 80,
'height' => 40,
'corners' => $default_corners,
],
'upscale_y' => [
'operation' => 'scale',
'arguments' => [
'height' => 40,
'upscale' => TRUE,
],
'width' => 80,
'height' => 40,
'corners' => $default_corners,
],
'crop' => [
'operation' => 'crop',
'arguments' => [
'x' => 12,
'y' => 4,
'width' => 16,
'height' => 12,
],
'width' => 16,
'height' => 12,
'corners' => array_fill(0, 4, static::WHITE),
],
'scale_and_crop' => [
'operation' => 'scale_and_crop',
'arguments' => [
'width' => 10,
'height' => 8,
],
'width' => 10,
'height' => 8,
'corners' => array_fill(0, 4, static::BLACK),
],
'convert_jpg' => [
'operation' => 'convert',
'width' => 40,
'height' => 20,
'arguments' => [
'extension' => 'jpeg',
],
'corners' => $default_corners,
],
'convert_gif' => [
'operation' => 'convert',
'width' => 40,
'height' => 20,
'arguments' => [
'extension' => 'gif',
],
'corners' => $default_corners,
],
'convert_png' => [
'operation' => 'convert',
'width' => 40,
'height' => 20,
'arguments' => [
'extension' => 'png',
],
'corners' => $default_corners,
],
'convert_webp' => [
'operation' => 'convert',
'width' => 40,
'height' => 20,
'arguments' => [
'extension' => 'webp',
],
'corners' => $default_corners,
],
'convert_avif' => [
'operation' => 'convert',
'width' => 40,
'height' => 20,
'arguments' => [
'extension' => 'avif',
],
'corners' => $default_corners,
],
];
// Systems using non-bundled GD2 may miss imagerotate(). Test if available.
if (function_exists('imagerotate')) {
$test_cases += [
'rotate_5' => [
'operation' => 'rotate',
// Fuchsia background.
'arguments' => [
'degrees' => 5,
'background' => '#FF00FF',
],
'width' => 40,
'height' => 23,
'corners' => PHP_VERSION_ID < 80500 ? array_fill(0, 4, static::FUCHSIA) : [
[
255,
0,
93,
0,
],
static::FUCHSIA,
static::FUCHSIA,
static::FUCHSIA,
],
],
'rotate_transparent_5' => [
'operation' => 'rotate',
'arguments' => [
'degrees' => 5,
],
'width' => 40,
'height' => 23,
'corners' => PHP_VERSION_ID < 80500 ? array_fill(0, 4, static::ROTATE_TRANSPARENT) : [
[
255,
93,
93,
46,
],
static::ROTATE_TRANSPARENT,
static::ROTATE_TRANSPARENT,
static::ROTATE_TRANSPARENT,
],
],
'rotate_90' => [
'operation' => 'rotate',
// Fuchsia background.
'arguments' => [
'degrees' => 90,
'background' => '#FF00FF',
],
'width' => 20,
'height' => 40,
'corners' => [
static::TRANSPARENT,
static::RED,
static::GREEN,
static::BLUE,
],
],
'rotate_transparent_90' => [
'operation' => 'rotate',
'arguments' => [
'degrees' => 90,
],
'width' => 20,
'height' => 40,
'corners' => [
static::TRANSPARENT,
static::RED,
static::GREEN,
static::BLUE,
],
],
];
}
// Systems using non-bundled GD2 may miss imagefilter(). Test if available.
if (function_exists('imagefilter')) {
$test_cases += [
'desaturate' => [
'operation' => 'desaturate',
'arguments' => [],
'height' => 20,
'width' => 40,
// Grayscale corners are a bit funky. Each of the corners are a shade
// of gray. The values of these were determined simply by looking at
// the final image to see what desaturated colors end up being.
'corners' => [
array_fill(0, 3, 76) + [
3 => 0,
],
array_fill(0, 3, 149) + [
3 => 0,
],
array_fill(0, 3, 29) + [
3 => 0,
],
array_fill(0, 3, 225) + [
3 => 127,
],
],
],
];
}
$ret = [];
foreach ($test_cases as $test_case => $values) {
$operation = $values['operation'];
$arguments = $values['arguments'];
unset($values['operation'], $values['arguments']);
$ret[$test_case] = [
$test_case,
$operation,
$arguments,
$values,
];
}
return $ret;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.