You are here

protected function CreateNew::execute in ImageMagick 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageToolkit/Operation/imagemagick/CreateNew.php \Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\CreateNew::execute()
  2. 8 src/Plugin/ImageToolkit/Operation/imagemagick/CreateNew.php \Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick\CreateNew::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/CreateNew.php, line 76

Class

CreateNew
Defines imagemagick CreateNew operation.

Namespace

Drupal\imagemagick\Plugin\ImageToolkit\Operation\imagemagick

Code

protected function execute(array $arguments) {
  $this
    ->getToolkit()
    ->setWidth($arguments['width'])
    ->setHeight($arguments['height'])
    ->setExifOrientation(NULL)
    ->setColorspace($this
    ->getToolkit()
    ->getExecManager()
    ->getPackage() === 'imagemagick' ? 'sRGB' : NULL)
    ->setProfiles([])
    ->setFrames(1);
  $this
    ->getToolkit()
    ->arguments()
    ->setSourceFormatFromExtension($arguments['extension'])
    ->setSourceLocalPath('')
    ->reset();
  $arg = '-size ' . $arguments['width'] . 'x' . $arguments['height'];

  // Transparent color syntax for GIF files differs by package.
  if ($arguments['extension'] === 'gif') {
    switch ($this
      ->getToolkit()
      ->getExecManager()
      ->getPackage()) {
      case 'imagemagick':
        $arg .= ' xc:transparent -transparent-color ' . $this
          ->escapeArgument($arguments['transparent_color']);
        break;
      case 'graphicsmagick':
        $arg .= ' xc:' . $this
          ->escapeArgument($arguments['transparent_color']) . ' -transparent ' . $this
          ->escapeArgument($arguments['transparent_color']);
        break;
    }
  }
  else {
    $arg .= ' xc:transparent';
  }
  $this
    ->addArgument($arg);
  return TRUE;
}