Composite.php in Imagick 8
File
src/Plugin/ImageToolkit/Operation/imagick/Composite.php
View source
<?php
namespace Drupal\imagick\Plugin\ImageToolkit\Operation\imagick;
use Imagick;
use Drupal\Core\Url;
use Drupal\Component\Utility\UrlHelper;
class Composite extends ImagickOperationBase {
protected function arguments() {
return [
'path' => [
'description' => 'Path to the composite image',
],
'composite' => [
'description' => 'Composite operator',
],
'x' => [
'description' => 'The column offset of the composited image',
],
'y' => [
'description' => 'he row offset of the composited image',
],
'channel' => [
'description' => 'Provide any channel constant that is valid for your channel mode. It is possible to apply more than one channel.',
],
];
}
protected function process(Imagick $resource, array $arguments) {
$path = $arguments['path'];
if (!UrlHelper::isExternal($path)) {
$path = \Drupal::service('file_system')
->realpath($path);
}
if (!file_exists($path)) {
return FALSE;
}
$composite = new Imagick($path);
$channel = array_reduce($arguments['channel'], function ($a, $b) {
return $a | $b;
}, 0);
return $resource
->compositeImage($composite, $arguments['composite'], $arguments['x'], $arguments['y'], $channel);
}
}