class SetCanvas in Image Effects 8
Same name in this branch
- 8 src/Plugin/ImageToolkit/Operation/gd/SetCanvas.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\gd\SetCanvas
- 8 src/Plugin/ImageToolkit/Operation/imagemagick/SetCanvas.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\SetCanvas
Same name and namespace in other branches
- 8.3 src/Plugin/ImageToolkit/Operation/imagemagick/SetCanvas.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\SetCanvas
- 8.2 src/Plugin/ImageToolkit/Operation/imagemagick/SetCanvas.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\SetCanvas
Defines ImageMagick set canvas operation.
Plugin annotation
@ImageToolkitOperation(
id = "image_effects_imagemagick_set_canvas",
toolkit = "imagemagick",
operation = "set_canvas",
label = @Translation("Set canvas"),
description = @Translation("Lay the image over a colored canvas.")
)
Hierarchy
- class \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\SetCanvas extends \Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\ImagemagickImageToolkitOperationBase uses ImagemagickOperationTrait, SetCanvasTrait
Expanded class hierarchy of SetCanvas
File
- src/
Plugin/ ImageToolkit/ Operation/ imagemagick/ SetCanvas.php, line 19
Namespace
Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagickView source
class SetCanvas extends ImagemagickImageToolkitOperationBase {
use ImagemagickOperationTrait;
use SetCanvasTrait;
/**
* {@inheritdoc}
*/
protected function execute(array $arguments) {
// Calculate geometry.
$geometry = sprintf('%dx%d', $arguments['width'], $arguments['height']);
if ($arguments['x_pos'] || $arguments['y_pos']) {
$geometry .= sprintf('%+d%+d', -$arguments['x_pos'], -$arguments['y_pos']);
}
// Determine background.
if ($arguments['canvas_color']) {
$bg = '-background ' . $this
->getToolkit()
->escapeShellArg($arguments['canvas_color']);
}
else {
$format = $this
->getToolkit()
->getDestinationFormat() ?: $this
->getToolkit()
->getSourceFormat();
$mime_type = $this
->getFormatMapper()
->getMimeTypeFromFormat($format);
if ($mime_type === 'image/jpeg') {
// JPEG does not allow transparency. Set to white.
// @todo allow to be configurable.
$bg = '-background ' . $this
->getToolkit()
->escapeShellArg('#FFFFFF');
}
else {
$bg = '-background transparent';
}
}
// Add argument.
$this
->getToolkit()
->addArgument("-gravity none {$bg} -compose src-over -extent {$geometry}");
// Set dimensions.
$this
->getToolkit()
->setWidth($arguments['width'])
->setHeight($arguments['height']);
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ImagemagickOperationTrait:: |
protected | property | The format mapper service. | |
ImagemagickOperationTrait:: |
protected | function | Returns the format mapper service. | |
SetCanvas:: |
protected | function | ||
SetCanvasTrait:: |
protected | function | ||
SetCanvasTrait:: |
protected | function |