MaskTrait.php in Image Effects 8.2
File
src/Plugin/ImageToolkit/Operation/MaskTrait.php
View source
<?php
namespace Drupal\image_effects\Plugin\ImageToolkit\Operation;
use Drupal\Core\Image\ImageInterface;
trait MaskTrait {
protected function arguments() {
return [
'mask_image' => [
'description' => 'Mask image.',
],
'mask_width' => [
'description' => 'Width of mask image.',
'required' => FALSE,
'default' => NULL,
],
'mask_height' => [
'description' => 'Height of mask image.',
'required' => FALSE,
'default' => NULL,
],
'x_offset' => [
'description' => 'X offset for mask image.',
'required' => FALSE,
'default' => 0,
],
'y_offset' => [
'description' => 'Y offset for mask image.',
'required' => FALSE,
'default' => 0,
],
];
}
protected function validateArguments(array $arguments) {
if (!$arguments['mask_image'] instanceof ImageInterface) {
throw new \InvalidArgumentException("Mask image passed to the 'mask' operation is invalid");
}
if (!$arguments['mask_image']
->isValid()) {
$source = $arguments['mask_image']
->getSource();
throw new \InvalidArgumentException("Invalid image at {$source}");
}
$arguments['mask_width'] = $arguments['mask_width'] !== NULL ? (int) $arguments['mask_width'] : NULL;
if ($arguments['mask_width'] !== NULL && $arguments['mask_width'] <= 0) {
throw new \InvalidArgumentException("Invalid mask width ('{$arguments['mask_width']}') specified for the image 'mask' operation");
}
$arguments['mask_height'] = $arguments['mask_height'] !== NULL ? (int) $arguments['mask_height'] : NULL;
if ($arguments['mask_height'] !== NULL && $arguments['mask_height'] <= 0) {
throw new \InvalidArgumentException("Invalid height ('{$arguments['mask_height']}') specified for the image 'mask' operation");
}
$arguments['x_offset'] = (int) $arguments['x_offset'];
$arguments['y_offset'] = (int) $arguments['y_offset'];
return $arguments;
}
}
Traits
Name |
Description |
MaskTrait |
Base trait for image_effects Mask operations. |