BackgroundTrait.php in Image Effects 8.3
File
src/Plugin/ImageToolkit/Operation/BackgroundTrait.php
View source
<?php
namespace Drupal\image_effects\Plugin\ImageToolkit\Operation;
use Drupal\Core\Image\ImageInterface;
trait BackgroundTrait {
protected function arguments() {
return [
'x_offset' => [
'description' => 'X offset for source image.',
],
'y_offset' => [
'description' => 'Y offset for source image.',
],
'opacity' => [
'description' => 'Opacity for source image.',
'required' => FALSE,
'default' => 100,
],
'background_image' => [
'description' => 'Image to use for background.',
],
];
}
protected function validateArguments(array $arguments) {
if ($arguments['opacity'] > 100 || $arguments['opacity'] < 0) {
throw new \InvalidArgumentException("Invalid opacity ('{$arguments['opacity']}') specified for the image 'background' operation");
}
if (!$arguments['background_image'] instanceof ImageInterface) {
throw new \InvalidArgumentException("Background image passed to the 'background' operation is invalid");
}
if (!$arguments['background_image']
->isValid()) {
$source = $arguments['background_image']
->getSource();
throw new \InvalidArgumentException("Invalid image at {$source}");
}
return $arguments;
}
}