Mask.php in Image Effects 8.3
File
src/Plugin/ImageToolkit/Operation/imagemagick/Mask.php
View source
<?php
namespace Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick;
use Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\ImagemagickImageToolkitOperationBase;
use Drupal\image_effects\Plugin\ImageToolkit\Operation\MaskTrait;
class Mask extends ImagemagickImageToolkitOperationBase {
use MaskTrait;
protected function execute(array $arguments) {
if ($this
->getToolkit()
->getExecManager()
->getPackage() === 'graphicsmagick') {
return FALSE;
}
$local_path = $arguments['mask_image']
->getToolkit()
->ensureSourceLocalPath();
if ($local_path !== '') {
$image_path = $this
->escapeArgument($local_path);
}
else {
$source_path = $arguments['mask_image']
->getToolkit()
->getSource();
throw new \InvalidArgumentException("Missing local path for image at {$source_path}");
}
$w = $arguments['mask_width'] ?: $arguments['mask_image']
->getToolkit()
->getWidth();
$h = $arguments['mask_height'] ?: $arguments['mask_image']
->getToolkit()
->getHeight();
$x = $arguments['x_offset'] >= 0 ? '+' . $arguments['x_offset'] : $arguments['x_offset'];
$y = $arguments['y_offset'] >= 0 ? '+' . $arguments['y_offset'] : $arguments['y_offset'];
$op = "-gravity None {$image_path} -geometry {$w}x{$h}!{$x}{$y} -alpha Off -compose CopyOpacity -composite -gravity none -background transparent -compose src-over -extent {$this->getToolkit()->getWidth()}x{$this->getToolkit()->getHeight()}";
$this
->addArgument($op);
return TRUE;
}
}
Classes
Name |
Description |
Mask |
Defines ImageMagick Mask operation. |