You are here

class Convolution in Image Effects 8

Same name in this branch
  1. 8 src/Plugin/ImageToolkit/Operation/gd/Convolution.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\gd\Convolution
  2. 8 src/Plugin/ImageToolkit/Operation/imagemagick/Convolution.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Convolution
Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageToolkit/Operation/imagemagick/Convolution.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Convolution
  2. 8.2 src/Plugin/ImageToolkit/Operation/imagemagick/Convolution.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Convolution

Defines ImageMagick Convolution operation.

Plugin annotation


@ImageToolkitOperation(
  id = "image_effects_imagemagick_convolution",
  toolkit = "imagemagick",
  operation = "convolution",
  label = @Translation("Convolution"),
  description = @Translation("Adjust image convolution.")
)

Hierarchy

  • class \Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick\Convolution extends \Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\ImagemagickImageToolkitOperationBase uses ConvolutionTrait

Expanded class hierarchy of Convolution

File

src/Plugin/ImageToolkit/Operation/imagemagick/Convolution.php, line 19

Namespace

Drupal\image_effects\Plugin\ImageToolkit\Operation\imagemagick
View source
class Convolution extends ImagemagickImageToolkitOperationBase {
  use ConvolutionTrait;

  /**
   * {@inheritdoc}
   */
  protected function execute(array $arguments) {
    if (isset($arguments['kernel']) && isset($arguments['divisor']) && isset($arguments['offset'])) {
      $matrix_s = '';
      foreach ($arguments['kernel'] as $vector) {
        $vector = array_map(function ($e) use ($arguments) {
          return $e / $arguments['divisor'] + $arguments['offset'];
        }, $vector);
        $matrix_s .= implode(',', $vector) . " ";
      }
      $matrix_s = substr($matrix_s, 0, -1);
      $this
        ->getToolkit()
        ->addArgument("-morphology Convolve '3x3:{$matrix_s}'");
    }
    return TRUE;
  }

}

Members