You are here

protected function BackgroundTrait::validateArguments in Image Effects 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageToolkit/Operation/BackgroundTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\BackgroundTrait::validateArguments()
  2. 8 src/Plugin/ImageToolkit/Operation/BackgroundTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\BackgroundTrait::validateArguments()

File

src/Plugin/ImageToolkit/Operation/BackgroundTrait.php, line 37

Class

BackgroundTrait
Base trait for image_effects Background operations.

Namespace

Drupal\image_effects\Plugin\ImageToolkit\Operation

Code

protected function validateArguments(array $arguments) {

  // Ensure source image opacity is in the range 0-100.
  if ($arguments['opacity'] > 100 || $arguments['opacity'] < 0) {
    throw new \InvalidArgumentException("Invalid opacity ('{$arguments['opacity']}') specified for the image 'background' operation");
  }

  // Ensure background_image is an expected ImageInterface object.
  if (!$arguments['background_image'] instanceof ImageInterface) {
    throw new \InvalidArgumentException("Background image passed to the 'background' operation is invalid");
  }

  // Ensure background_image is a valid image.
  if (!$arguments['background_image']
    ->isValid()) {
    $source = $arguments['background_image']
      ->getSource();
    throw new \InvalidArgumentException("Invalid image at {$source}");
  }
  return $arguments;
}