protected function Mask::execute in Image Effects 8.2
Same name in this branch
- 8.2 src/Plugin/ImageToolkit/Operation/gd/Mask.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\gd\Mask::execute()
- 8.2 src/Plugin/ImageToolkit/Operation/imagemagick/Mask.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Mask::execute()
Same name and namespace in other branches
- 8.3 src/Plugin/ImageToolkit/Operation/imagemagick/Mask.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Mask::execute()
- 8 src/Plugin/ImageToolkit/Operation/imagemagick/Mask.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Mask::execute()
File
- src/
Plugin/ ImageToolkit/ Operation/ imagemagick/ Mask.php, line 26
Class
- Mask
- Defines ImageMagick Mask operation.
Namespace
Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagickCode
protected function execute(array $arguments) {
if ($this
->getToolkit()
->getExecManager()
->getPackage() === 'graphicsmagick') {
// GraphicsMagick does not support this operation, return early.
// @todo implement a GraphicsMagick solution if possible.
return FALSE;
}
// Mask image local path.
$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}");
}
// Set the dimensions of the mask. Use of the scale option means that we
// need to change the dimensions: always set them, they don't harm when the
// scale option is not used.
$w = $arguments['mask_width'] ?: $arguments['mask_image']
->getToolkit()
->getWidth();
$h = $arguments['mask_height'] ?: $arguments['mask_image']
->getToolkit()
->getHeight();
// Set offset. Offset arguments require a sign in front.
$x = $arguments['x_offset'] >= 0 ? '+' . $arguments['x_offset'] : $arguments['x_offset'];
$y = $arguments['y_offset'] >= 0 ? '+' . $arguments['y_offset'] : $arguments['y_offset'];
// Prepare argument.
$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;
}