protected function DefineCanvas::process in Imagick 8
File
- src/
Plugin/ ImageToolkit/ Operation/ imagick/ DefineCanvas.php, line 47
Class
- DefineCanvas
- Defines imagick define canvas operation.
Namespace
Drupal\imagick\Plugin\ImageToolkit\Operation\imagickCode
protected function process(Imagick &$resource, array $arguments) {
$color = $arguments['HEX'];
$under = $arguments['under'];
$exact_size = $arguments['exact_measurements'];
$exact = $arguments['exact'];
$relative = $arguments['relative'];
$canvas = new Imagick();
$canvas
->setFormat($resource
->getImageFormat());
$color = empty($color) ? 'none' : $color;
if ($exact_size) {
$width = $this::imagick_percent_filter($exact['width'], $resource
->getImageWidth());
$height = $this::imagick_percent_filter($exact['height'], $resource
->getImageHeight());
list($x, $y) = explode('-', $exact['anchor']);
$x = image_filter_keyword($x, $width, $resource
->getImageWidth());
$y = image_filter_keyword($y, $height, $resource
->getImageHeight());
}
else {
$width = $resource
->getImageWidth() + $relative['leftdiff'] + $relative['rightdiff'];
$height = $resource
->getImageHeight() + $relative['topdiff'] + $relative['bottomdiff'];
$x = $relative['leftdiff'];
$y = $relative['topdiff'];
}
if (!$canvas
->newImage($width, $height, new ImagickPixel($color))) {
return FALSE;
}
if ($under && !$canvas
->compositeImage($resource, Imagick::COMPOSITE_DEFAULT, $x, $y)) {
return FALSE;
}
$resource = clone $canvas;
return TRUE;
}