You are here

protected function TransparentBackground::execute in Imagick 8

Overrides ImagickOperationTrait::execute

File

src/Plugin/ImageToolkit/Operation/imagick/TransparentBackground.php, line 30

Class

TransparentBackground
Defines imagick transparent background operation.

Namespace

Drupal\imagick\Plugin\ImageToolkit\Operation\imagick

Code

protected function execute(array $arguments = []) {

  /* @var $resource Imagick */
  $resource = $this
    ->getToolkit()
    ->getResource();

  // Replace white background with fuchsia
  $floodSuccess = $resource
    ->floodFillPaintImage("rgb(255, 0, 255)", 2500, "rgb(255,255,255)", 0, 0, false);

  // Make fuchsia transparent
  $transparentSuccess = $resource
    ->transparentPaintImage("rgb(255,0,255)", 0, 10, FALSE);

  // Format as PNG
  $formatSuccess = $resource
    ->setImageFormat('PNG');
  return $floodSuccess && $transparentSuccess;
}