SetCanvas.php in Image Effects 8.2
File
src/Plugin/ImageToolkit/Operation/imagemagick/SetCanvas.php
View source
<?php
namespace Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick;
use Drupal\image_effects\Plugin\ImageToolkit\Operation\SetCanvasTrait;
use Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\ImagemagickImageToolkitOperationBase;
class SetCanvas extends ImagemagickImageToolkitOperationBase {
use ImagemagickOperationTrait;
use SetCanvasTrait;
protected function execute(array $arguments) {
$toolkit_arguments = $this
->getToolkit()
->arguments();
$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']);
}
if ($arguments['canvas_color']) {
$bg = '-background ' . $this
->escapeArgument($arguments['canvas_color']);
}
else {
$format = $toolkit_arguments
->getDestinationFormat() ?: $toolkit_arguments
->getSourceFormat();
$mime_type = $this
->getFormatMapper()
->getMimeTypeFromFormat($format);
if ($mime_type === 'image/jpeg') {
$bg = '-background ' . $this
->escapeArgument('#FFFFFF');
}
else {
$bg = '-background transparent';
}
}
$this
->addArgument("-gravity none {$bg} -compose src-over -extent {$geometry}");
$this
->getToolkit()
->setWidth($arguments['width'])
->setHeight($arguments['height']);
return TRUE;
}
}
Classes
Name |
Description |
SetCanvas |
Defines ImageMagick set canvas operation. |