View source
<?php
namespace Drupal\Tests\image_effects\Functional\Effect;
use Drupal\Tests\image_effects\Functional\ImageEffectsTestBase;
class MaskTest extends ImageEffectsTestBase {
public function providerToolkits() {
$toolkits = parent::providerToolkits();
unset($toolkits['ImageMagick-graphicsmagick']);
return $toolkits;
}
public function testMaskEffect($toolkit_id, $toolkit_config, array $toolkit_settings) {
$this
->changeToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
$original_uri = $this
->getTestImageCopyUri('/tests/images/fuchsia.png', 'image_effects');
$derivative_uri = $this->testImageStyle
->buildUri($original_uri);
$mask_uri = $this
->getTestImageCopyUri('/tests/images/image-mask.png', 'image_effects');
$effect = [
'id' => 'image_effects_mask',
'data' => [
'mask_image' => $mask_uri,
'placement' => 'left-top',
],
];
$uuid = $this
->addEffectToTestStyle($effect);
$this->testImageStyle
->createDerivative($original_uri, $derivative_uri);
$image = $this->imageFactory
->get($derivative_uri, 'gd');
$this
->assertColorsAreEqual($this->fuchsia, $this
->getPixelColor($image, 0, 0));
$this
->assertColorsAreEqual($this->transparent, $this
->getPixelColor($image, 39, 0));
$this
->assertColorsAreEqual($this->transparent, $this
->getPixelColor($image, 0, 19));
$this
->assertColorsAreEqual($this->fuchsia, $this
->getPixelColor($image, 39, 19));
$this
->assertColorsAreEqual($this->transparent, $this
->getPixelColor($image, 79, 0));
$this
->assertColorsAreEqual($this->transparent, $this
->getPixelColor($image, 0, 59));
$this
->assertColorsAreEqual($this->transparent, $this
->getPixelColor($image, 79, 59));
$this
->removeEffectFromTestStyle($uuid);
$effect = [
'id' => 'image_effects_mask',
'data' => [
'mask_image' => $mask_uri,
'mask_resize][mask_width][c0][c1][value' => 100,
'mask_resize][mask_width][c0][c1][uom' => 'perc',
'mask_resize][mask_height][c0][c1][value' => 100,
'mask_resize][mask_height][c0][c1][uom' => 'perc',
'placement' => 'left-top',
],
];
$uuid = $this
->addEffectToTestStyle($effect);
$this->testImageStyle
->createDerivative($original_uri, $derivative_uri);
$image = $this->imageFactory
->get($derivative_uri, 'gd');
$this
->assertColorsAreEqual($this->fuchsia, $this
->getPixelColor($image, 0, 0));
$this
->assertColorsAreEqual($this->transparent, $this
->getPixelColor($image, 79, 0));
$this
->assertColorsAreEqual($this->transparent, $this
->getPixelColor($image, 0, 59));
$this
->assertColorsAreEqual($this->fuchsia, $this
->getPixelColor($image, 79, 59));
$this
->removeEffectFromTestStyle($uuid);
}
}