Background.php in Image Effects 8.3
File
src/Plugin/ImageToolkit/Operation/imagemagick/Background.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\BackgroundTrait;
class Background extends ImagemagickImageToolkitOperationBase {
use BackgroundTrait;
protected function execute(array $arguments) {
$local_path = $arguments['background_image']
->getToolkit()
->ensureSourceLocalPath();
if ($local_path !== '') {
$image_path = $this
->escapeArgument($local_path);
}
else {
$source_path = $arguments['background_image']
->getToolkit()
->getSource();
throw new \InvalidArgumentException("Missing local path for image at {$source_path}");
}
$op = '-gravity None';
$op .= " -background transparent";
$w = $arguments['background_image']
->getToolkit()
->getWidth();
$h = $arguments['background_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 .= " -extent {$w}x{$h}{$x}{$y} ";
$op .= $image_path;
if ($arguments['opacity'] == 100) {
$op .= ' -compose dst-over -composite';
}
else {
$op .= " -compose blend -define compose:args=100,{$arguments['opacity']} -composite";
}
$this
->addArgument($op);
$this
->getToolkit()
->setWidth($w)
->setHeight($h);
return TRUE;
}
}