Coloroverlay.php in Imagick 8
File
src/Plugin/ImageToolkit/Operation/imagick/Coloroverlay.php
View source
<?php
namespace Drupal\imagick\Plugin\ImageToolkit\Operation\imagick;
use Imagick;
class Coloroverlay extends ImagickOperationBase {
protected function arguments() {
return [
'HEX' => [
'description' => 'The color used to create the overlay.',
],
'alpha' => [
'description' => 'The transparency of the overlay layer.',
],
];
}
protected function process(Imagick $resource, array $arguments) {
$color = new Imagick();
$color
->newImage($resource
->getImageWidth(), $resource
->getImageHeight(), $arguments['HEX']);
$alpha = $arguments['alpha'] / 100;
if (method_exists($color, 'setImageOpacity')) {
$color
->setImageOpacity($alpha);
}
else {
$color
->setImageAlpha($alpha);
}
return $resource
->compositeImage($color, Imagick::COMPOSITE_DEFAULT, 0, 0);
}
}