You are here

class Replace in Image Replace 8

Same name in this branch
  1. 8 src/Plugin/ImageToolkit/Operation/gd/Replace.php \Drupal\image_replace\Plugin\ImageToolkit\Operation\gd\Replace
  2. 8 src/Plugin/ImageToolkit/Operation/imagemagick/Replace.php \Drupal\image_replace\Plugin\ImageToolkit\Operation\imagemagick\Replace

Defines Imagegemagick image_replace operation.

Plugin annotation


@ImageToolkitOperation(
  id = "image_replace_imagemagick",
  toolkit = "imagemagick",
  operation = "image_replace",
  label = @Translation("Replace"),
  description = @Translation("Swap the original image with a replacement image."),
)

Hierarchy

  • class \Drupal\image_replace\Plugin\ImageToolkit\Operation\imagemagick\Replace extends \Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\ImagemagickImageToolkitOperationBase

Expanded class hierarchy of Replace

File

src/Plugin/ImageToolkit/Operation/imagemagick/Replace.php, line 20

Namespace

Drupal\image_replace\Plugin\ImageToolkit\Operation\imagemagick
View source
class Replace extends ImagemagickImageToolkitOperationBase {

  /**
   * {@inheritdoc}
   */
  protected function arguments() {
    return array(
      'replacement_image' => array(
        'description' => 'The replacement image',
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  protected function validateArguments(array $arguments) {
    if (!($arguments['replacement_image'] instanceof ImageInterface || !$arguments['replacement_image']
      ->getToolkit() instanceof ImagemagickToolkit)) {
      throw new \InvalidArgumentException("Invalid replacement image specified for the 'image_replace' operation.");
    }
    return $arguments;
  }

  /**
   * {@inheritdoc}
   */
  protected function execute(array $arguments = array()) {
    $replacement = $arguments['replacement_image']
      ->getToolkit();

    // Replace original image's source with replacement image's source
    $this
      ->getToolkit()
      ->arguments()
      ->setSource($replacement
      ->arguments()
      ->getSource());
    $this
      ->getToolkit()
      ->setWidth($replacement
      ->getWidth())
      ->setHeight($replacement
      ->getHeight());
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Replace::arguments protected function
Replace::execute protected function
Replace::validateArguments protected function