Watermark.php in Image Effects 8
File
src/Plugin/ImageToolkit/Operation/imagemagick/Watermark.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\WatermarkTrait;
class Watermark extends ImagemagickImageToolkitOperationBase {
use WatermarkTrait;
protected function execute(array $arguments) {
$local_path = $arguments['watermark_image']
->getToolkit()
->getSourceLocalPath();
if ($local_path !== '') {
$image_path = $this
->getToolkit()
->escapeShellArg($local_path);
}
else {
$source_path = $arguments['watermark_image']
->getToolkit()
->getSource();
throw new \InvalidArgumentException("Missing local path for image at {$source_path}");
}
$w = $arguments['watermark_width'] ?: $arguments['watermark_image']
->getToolkit()
->getWidth();
$h = $arguments['watermark_height'] ?: $arguments['watermark_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'];
switch ($this
->getToolkit()
->getPackage()) {
case 'imagemagick':
if ($arguments['opacity'] == 100) {
$op = "-gravity None {$image_path} -geometry {$w}x{$h}!{$x}{$y} -compose src-over -composite";
}
else {
$op = "-gravity None {$image_path} -geometry {$w}x{$h}!{$x}{$y} -compose blend -define compose:args={$arguments['opacity']} -composite";
}
break;
case 'graphicsmagick':
$op = "-draw 'image Over {$arguments['x_offset']},{$arguments['y_offset']} {$w},{$h} {$image_path}'";
break;
}
$this
->getToolkit()
->addArgument($op);
return TRUE;
}
}
Classes
Name |
Description |
Watermark |
Defines ImageMagick Watermark operation. |