protected function Opacity::execute in Image Effects 8.2
Same name in this branch
- 8.2 src/Plugin/ImageToolkit/Operation/gd/Opacity.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\gd\Opacity::execute()
- 8.2 src/Plugin/ImageToolkit/Operation/imagemagick/Opacity.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Opacity::execute()
Same name and namespace in other branches
- 8.3 src/Plugin/ImageToolkit/Operation/imagemagick/Opacity.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Opacity::execute()
- 8 src/Plugin/ImageToolkit/Operation/imagemagick/Opacity.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Opacity::execute()
File
- src/
Plugin/ ImageToolkit/ Operation/ imagemagick/ Opacity.php, line 26
Class
- Opacity
- Defines ImageMagick Opacity operation.
Namespace
Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagickCode
protected function execute(array $arguments) {
if ($this
->getToolkit()
->getExecManager()
->getPackage() === 'graphicsmagick') {
// GraphicsMagick does not support -alpha argument, return early.
// @todo implement a GraphicsMagick solution if possible.
return FALSE;
}
switch ($arguments['opacity']) {
case 100:
// Fully opaque, leave image as-is.
break;
case 0:
// Fully transparent, set full transparent for all pixels.
$this
->addArgument("-alpha set -channel Alpha -evaluate Set 0%");
break;
default:
// Divide existing alpha to the opacity needed. This preserves
// partially transparent images.
$divide = number_format((double) (100 / $arguments['opacity']), 4, '.', ',');
$this
->addArgument("-alpha set -channel Alpha -evaluate Divide {$divide}");
break;
}
return TRUE;
}