View source
<?php
namespace Drupal\Tests\image_effects\Functional\Effect;
use Drupal\Tests\image_effects\Functional\ImageEffectsTestBase;
class GaussianBlurTest extends ImageEffectsTestBase {
public function testGaussianBlurEffect($toolkit_id, $toolkit_config, array $toolkit_settings) {
$this
->changeToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
$effect = [
'id' => 'image_effects_gaussian_blur',
'data' => [
'radius' => 3,
'sigma' => 2,
],
];
$this
->addEffectToTestStyle($effect);
$original_uri = $this
->getTestImageCopyUri('/tests/images/red-on-green.png', 'image_effects');
$derivative_uri = $this->testImageStyle
->buildUri($original_uri);
$this->testImageStyle
->createDerivative($original_uri, $derivative_uri);
$image = $this->imageFactory
->get($derivative_uri, 'gd');
$this
->assertColorsAreEqual($this->green, $this
->getPixelColor($image, 0, 0));
$this
->assertColorsAreEqual($this->red, $this
->getPixelColor($image, 50, 50));
$this
->assertColorsAreEqual([
94,
161,
0,
0,
], $this
->getPixelColor($image, 25, 25));
$original_uri = $this
->getTestImageCopyUri('/tests/images/red-on-transparent.png', 'image_effects');
$derivative_uri = $this->testImageStyle
->buildUri($original_uri);
$this->testImageStyle
->createDerivative($original_uri, $derivative_uri);
$image = $this->imageFactory
->get($derivative_uri, 'gd');
$this
->assertColorsAreEqual($this->transparent, $this
->getPixelColor($image, 0, 0));
$this
->assertColorsAreEqual($this->red, $this
->getPixelColor($image, 50, 50));
$this
->assertEqual(80, imagecolorsforindex($image
->getToolkit()
->getResource(), imagecolorat($image
->getToolkit()
->getResource(), 25, 25))['alpha']);
}
}