View source  
  <?php
namespace Drupal\Tests\image_effects\Functional\Effect;
use Drupal\Tests\image_effects\Functional\ImageEffectsTestBase;
class OpacityTest extends ImageEffectsTestBase {
  
  public function providerToolkits() {
    $toolkits = parent::providerToolkits();
    
    unset($toolkits['ImageMagick-graphicsmagick']);
    return $toolkits;
  }
  
  public function testOpacityEffect($toolkit_id, $toolkit_config, array $toolkit_settings) {
    $this
      ->changeToolkit($toolkit_id, $toolkit_config, $toolkit_settings);
    
    $original_uri = $this
      ->getTestImageCopyUri('core/tests/fixtures/files/image-test.png');
    
    $test_data = [
      
      '100' => [
        $this->red,
        $this->green,
        $this->transparent,
        $this->blue,
      ],
      
      '50' => [
        [
          255,
          0,
          0,
          63,
        ],
        [
          0,
          255,
          0,
          63,
        ],
        $this->transparent,
        [
          0,
          0,
          255,
          63,
        ],
      ],
      
      '0' => [
        $this->transparent,
        $this->transparent,
        $this->transparent,
        $this->transparent,
      ],
    ];
    foreach ($test_data as $opacity => $colors) {
      
      $effect = [
        'id' => 'image_effects_opacity',
        'data' => [
          'opacity' => $opacity,
        ],
      ];
      $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
        ->assertColorsAreEqual($colors[0], $this
        ->getPixelColor($image, 0, 0));
      $this
        ->assertColorsAreEqual($colors[1], $this
        ->getPixelColor($image, 39, 0));
      $this
        ->assertColorsAreEqual($colors[2], $this
        ->getPixelColor($image, 0, 19));
      $this
        ->assertColorsAreEqual($colors[3], $this
        ->getPixelColor($image, 39, 19));
      
      $uuid = $this
        ->removeEffectFromTestStyle($uuid);
    }
  }
}