class Watermark in Image Effects 8.3
Same name in this branch
- 8.3 src/Plugin/ImageToolkit/Operation/gd/Watermark.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\gd\Watermark
- 8.3 src/Plugin/ImageToolkit/Operation/imagemagick/Watermark.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Watermark
Same name and namespace in other branches
- 8 src/Plugin/ImageToolkit/Operation/imagemagick/Watermark.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Watermark
- 8.2 src/Plugin/ImageToolkit/Operation/imagemagick/Watermark.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Watermark
Defines ImageMagick Watermark operation.
Plugin annotation
@ImageToolkitOperation(
id = "image_effects_imagemagick_watermark",
toolkit = "imagemagick",
operation = "watermark",
label = @Translation("Watermark"),
description = @Translation("Add watermark image effect.")
)
Hierarchy
- class \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Watermark extends \Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\ImagemagickImageToolkitOperationBase uses WatermarkTrait
Expanded class hierarchy of Watermark
File
- src/
Plugin/ ImageToolkit/ Operation/ imagemagick/ Watermark.php, line 19
Namespace
Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagickView source
class Watermark extends ImagemagickImageToolkitOperationBase {
use WatermarkTrait;
/**
* {@inheritdoc}
*/
protected function execute(array $arguments) {
// Watermark image local path.
$local_path = $arguments['watermark_image']
->getToolkit()
->ensureSourceLocalPath();
if ($local_path !== '') {
$image_path = $this
->escapeArgument($local_path);
}
else {
$source_path = $arguments['watermark_image']
->getToolkit()
->getSource();
throw new \InvalidArgumentException("Missing local path for image at {$source_path}");
}
// Set the dimensions of the overlay.
$w = $arguments['watermark_width'] ?: $arguments['watermark_image']
->getToolkit()
->getWidth();
$h = $arguments['watermark_height'] ?: $arguments['watermark_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'];
// Compose it with the destination.
switch ($this
->getToolkit()
->getExecManager()
->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':
// @todo see if GraphicsMagick can support opacity setting.
$op = "-draw 'image Over {$arguments['x_offset']},{$arguments['y_offset']} {$w},{$h} {$image_path}'";
break;
}
$this
->addArgument($op);
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Watermark:: |
protected | function | ||
WatermarkTrait:: |
protected | function | ||
WatermarkTrait:: |
protected | function |