You are here

protected function Rotate::execute in ImageMagick 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/ImageToolkit/Operation/imagemagick/Rotate.php \Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\Rotate::execute()
  2. 8.2 src/Plugin/ImageToolkit/Operation/imagemagick/Rotate.php \Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\Rotate::execute()

Performs the actual manipulation on the image.

Image toolkit operation implementers must implement this method. This method is responsible for actually performing the operation on the image. When this method gets called, the implementer may assume all arguments, also the optional ones, to be available, validated and corrected.

Parameters

array $arguments: An associative array of arguments to be used by the toolkit operation.

Return value

bool TRUE if the operation was performed successfully, FALSE otherwise.

Overrides ImageToolkitOperationBase::execute

File

src/Plugin/ImageToolkit/Operation/imagemagick/Rotate.php, line 63

Class

Rotate
Defines imagemagick Rotate operation.

Namespace

Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick

Code

protected function execute(array $arguments) {

  // Rotate.
  $arg = '-background ' . $this
    ->escapeArgument($arguments['background']);
  $arg .= ' -rotate ' . $arguments['degrees'];
  $arg .= ' +repage';
  $this
    ->addArgument($arg);

  // Need to resize the image after rotation to make sure it complies with
  // the dimensions expected, calculated via the Rectangle class.
  if ($this
    ->getToolkit()
    ->getWidth() && $this
    ->getToolkit()
    ->getHeight()) {
    $box = new Rectangle($this
      ->getToolkit()
      ->getWidth(), $this
      ->getToolkit()
      ->getHeight());
    $box = $box
      ->rotate((double) $arguments['degrees']);
    return $this
      ->getToolkit()
      ->apply('resize', [
      'width' => $box
        ->getBoundingWidth(),
      'height' => $box
        ->getBoundingHeight(),
      'filter' => $arguments['resize_filter'],
    ]);
  }
  return TRUE;
}