You are here

trait ConvolutionTrait in Image Effects 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageToolkit/Operation/ConvolutionTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\ConvolutionTrait
  2. 8 src/Plugin/ImageToolkit/Operation/ConvolutionTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\ConvolutionTrait

Base trait for image_effects Convolution operations.

Hierarchy

2 files declare their use of ConvolutionTrait
Convolution.php in src/Plugin/ImageToolkit/Operation/gd/Convolution.php
Convolution.php in src/Plugin/ImageToolkit/Operation/imagemagick/Convolution.php

File

src/Plugin/ImageToolkit/Operation/ConvolutionTrait.php, line 8

Namespace

Drupal\image_effects\Plugin\ImageToolkit\Operation
View source
trait ConvolutionTrait {

  /**
   * {@inheritdoc}
   */
  protected function arguments() {
    return [
      'kernel' => [
        'description' => 'The convolution kernel matrix.',
      ],
      'divisor' => [
        'description' => 'Typically the matrix entries sum (normalization).',
      ],
      'offset' => [
        'description' => 'This value is added to the division result.',
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  protected function validateArguments(array $arguments) {

    // Ensure convolution parameters are valid.
    foreach ($arguments['kernel'] as $row) {
      foreach ($row as $kernel_entry) {
        if (!is_numeric($kernel_entry)) {
          throw new \InvalidArgumentException("Invalid kernel entry ('{$arguments['divisor']}') specified for the image 'convolution' operation");
        }
      }
    }
    if (!is_numeric($arguments['divisor'])) {
      throw new \InvalidArgumentException("Invalid divisor ('{$arguments['divisor']}') specified for the image 'convolution' operation");
    }
    if (!is_numeric($arguments['offset'])) {
      throw new \InvalidArgumentException("Invalid offset ('{$arguments['offset']}') specified for the image 'convolution' operation");
    }
    return $arguments;
  }

}

Members