You are here

protected function ImagemagickToolkit::parseFileViaGetImageSize in ImageMagick 8.2

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

Parses the image file using the file metadata 'getimagesize' plugin.

Return value

bool TRUE if the file could be found and is an image, FALSE otherwise.

Deprecated

in 8.x-2.3, will be removed in 8.x-3.0. Use parseFileViaIdentify() instead.

See also

https://www.drupal.org/project/imagemagick/issues/2938377

1 call to ImagemagickToolkit::parseFileViaGetImageSize()
ImagemagickToolkit::parseFile in src/Plugin/ImageToolkit/ImagemagickToolkit.php
Determines if a file contains a valid image.

File

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

Class

ImagemagickToolkit
Provides ImageMagick integration toolkit for image manipulation.

Namespace

Drupal\imagemagick\Plugin\ImageToolkit

Code

protected function parseFileViaGetImageSize() {
  @trigger_error('Image file parsing via \'getimagesize\' is deprecated in 8.x-2.3, will be removed in 8.x-3.0. Use parsing via \'identify\' instead. See https://www.drupal.org/project/imagemagick/issues/2938377.', E_USER_DEPRECATED);

  // Allow modules to alter the source file.
  $this->moduleHandler
    ->alter('imagemagick_pre_parse_file', $this->arguments);

  // Get 'getimagesize' metadata for this image.
  if (!($file_md = $this->fileMetadataManager
    ->uri($this
    ->getSource()))) {

    // No file, return.
    return FALSE;
  }
  if (!($data = $file_md
    ->getMetadata('getimagesize'))) {

    // No data, return.
    return FALSE;
  }

  // Process parsed data.
  $format = $this->formatMapper
    ->getFormatFromExtension(image_type_to_extension($data[2], FALSE));
  if ($format) {
    $this
      ->setWidth($data[0])
      ->setHeight($data[1])
      ->setExifOrientation(static::EXIF_ORIENTATION_NOT_FETCHED)
      ->setFrames(NULL);
    $this
      ->arguments()
      ->setSourceFormat($format);
    return TRUE;
  }
  return FALSE;
}