You are here

protected function ImagemagickToolkit::convert in ImageMagick 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/ImageToolkit/ImagemagickToolkit.php \Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit::convert()
  2. 8.2 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 781

Class

ImagemagickToolkit
Provides ImageMagick integration toolkit for image manipulation.

Namespace

Drupal\imagemagick\Plugin\ImageToolkit

Code

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

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

  // Allow modules to alter the command line parameters.
  $command = 'convert';
  $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());
}