View source
<?php
namespace Drupal\Tests\image_effects\Functional\Effect;
use Drupal\Tests\image_effects\Functional\ImageEffectsTestBase;
class ContrastTest extends ImageEffectsTestBase {
public function providerToolkits() {
$toolkits = parent::providerToolkits();
unset($toolkits['ImageMagick-graphicsmagick']);
return $toolkits;
}
public function testContrastEffect($toolkit_id, $toolkit_config, array $toolkit_settings) {
$this
->changeToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
$original_uri = $this
->getTestImageCopyUri('/files/image-test.png', 'simpletest');
$test_data = [
'0' => [
'colors' => [
$this->red,
$this->green,
$this->transparent,
$this->blue,
],
'tolerance' => 0,
],
'-50' => [
'colors' => [
[
180,
75,
75,
0,
],
[
75,
180,
75,
0,
],
$this->transparent,
[
75,
75,
180,
0,
],
],
'tolerance' => 2000,
],
'-100' => [
'colors' => [
$this->grey,
$this->grey,
$this->transparent,
$this->grey,
],
'tolerance' => 16000,
],
'50' => [
'colors' => [
$this->red,
$this->green,
$this->transparent,
$this->blue,
],
'tolerance' => 0,
],
'100' => [
'colors' => [
$this->red,
$this->green,
$this->transparent,
$this->blue,
],
'tolerance' => 0,
],
];
foreach ($test_data as $key => $entry) {
$effect = [
'id' => 'image_effects_contrast',
'data' => [
'level' => $key,
],
];
$uuid = $this
->addEffectToTestStyle($effect);
$derivative_uri = $this->testImageStyle
->buildUri($original_uri);
$this->testImageStyle
->createDerivative($original_uri, $derivative_uri);
$image = $this->imageFactory
->get($derivative_uri, 'gd');
$this
->assertColorsAreClose($entry['colors'][0], $this
->getPixelColor($image, 0, 0), $entry['tolerance']);
$this
->assertColorsAreClose($entry['colors'][1], $this
->getPixelColor($image, 39, 0), $entry['tolerance']);
$this
->assertColorsAreClose($entry['colors'][2], $this
->getPixelColor($image, 0, 19), $entry['tolerance']);
$this
->assertColorsAreClose($entry['colors'][3], $this
->getPixelColor($image, 39, 19), $entry['tolerance']);
$uuid = $this
->removeEffectFromTestStyle($uuid);
}
}
}