You are here

protected function ImagemagickToolkit::convert in ImageMagick 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageToolkit/ImagemagickToolkit.php \Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit::convert()
  2. 8 src/Plugin/ImageToolkit/ImagemagickToolkit.php \Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit::convert()

Calls the convert executable with the specified arguments.

Return value

bool TRUE if the file could be converted, FALSE otherwise.

1 call to ImagemagickToolkit::convert()
ImagemagickToolkit::save in src/Plugin/ImageToolkit/ImagemagickToolkit.php
Writes an image resource to a destination file.

File

src/Plugin/ImageToolkit/ImagemagickToolkit.php, line 1326

Class

ImagemagickToolkit
Provides ImageMagick integration toolkit for image manipulation.

Namespace

Drupal\imagemagick\Plugin\ImageToolkit

Code

protected function convert() {
  $config = $this->configFactory
    ->get('imagemagick.settings');

  // Ensure sourceLocalPath is prepared.
  $this
    ->ensureSourceLocalPath();

  // Allow modules to alter the command line parameters.
  $command = 'convert';
  $this->moduleHandler
    ->alterDeprecated('Deprecated in 8.x-2.5, will be removed in 8.x-3.0. Use an event subscriber to react on a ImagemagickExecutionEvent::PRE_IDENTIFY_EXECUTE or a ImagemagickExecutionEvent::PRE_CONVERT_EXECUTE event. See https://www.drupal.org/project/imagemagick/issues/3043136.', 'imagemagick_arguments', $this->arguments, $command);
  $this->eventDispatcher
    ->dispatch(ImagemagickExecutionEvent::PRE_CONVERT_EXECUTE, new ImagemagickExecutionEvent($this->arguments));

  // Delete any cached file metadata for the destination image file, before
  // creating a new one, and release the URI from the manager so that
  // metadata will not stick in the same request.
  $this->fileMetadataManager
    ->deleteCachedMetadata($this
    ->arguments()
    ->getDestination());
  $this->fileMetadataManager
    ->release($this
    ->arguments()
    ->getDestination());

  // When destination format differs from source format, and source image
  // is multi-frame, convert only the first frame.
  $destination_format = $this
    ->arguments()
    ->getDestinationFormat() ?: $this
    ->arguments()
    ->getSourceFormat();
  if ($this
    ->arguments()
    ->getSourceFormat() !== $destination_format && ($this
    ->getFrames() === NULL || $this
    ->getFrames() > 1)) {
    $this
      ->arguments()
      ->setSourceFrames('[0]');
  }

  // Execute the command and return.
  return $this
    ->getExecManager()
    ->execute($command, $this->arguments) && file_exists($this
    ->arguments()
    ->getDestinationLocalPath());
}