protected function ImagemagickToolkit::parseFileViaIdentify in ImageMagick 8.2
Same name and namespace in other branches
- 8 src/Plugin/ImageToolkit/ImagemagickToolkit.php \Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit::parseFileViaIdentify()
Parses the image file using the 'identify' executable.
Return value
bool TRUE if the file could be found and is an image, FALSE otherwise.
1 call to ImagemagickToolkit::parseFileViaIdentify()
- ImagemagickToolkit::parseFile in src/
Plugin/ ImageToolkit/ ImagemagickToolkit.php - Determines if a file contains a valid image.
File
- src/
Plugin/ ImageToolkit/ ImagemagickToolkit.php, line 1234
Class
- ImagemagickToolkit
- Provides ImageMagick integration toolkit for image manipulation.
Namespace
Drupal\imagemagick\Plugin\ImageToolkitCode
protected function parseFileViaIdentify() {
// Get 'imagemagick_identify' metadata for this image. The file metadata
// plugin will fetch it from the file via the ::identify() method if data
// is not already available.
if (!($file_md = $this->fileMetadataManager
->uri($this
->getSource()))) {
// No file, return.
return FALSE;
}
if (!$file_md
->getMetadata(static::FILE_METADATA_PLUGIN_ID)) {
// No data, return.
return FALSE;
}
// Sets the local file path to the one retrieved by identify if available.
if ($source_local_path = $file_md
->getMetadata(static::FILE_METADATA_PLUGIN_ID, 'source_local_path')) {
$this
->arguments()
->setSourceLocalPath($source_local_path);
}
// Process parsed data from the first frame.
$format = $file_md
->getMetadata(static::FILE_METADATA_PLUGIN_ID, 'format');
if ($this->formatMapper
->isFormatEnabled($format)) {
$this
->setWidth((int) $file_md
->getMetadata(static::FILE_METADATA_PLUGIN_ID, 'width'))
->setHeight((int) $file_md
->getMetadata(static::FILE_METADATA_PLUGIN_ID, 'height'))
->setExifOrientation($file_md
->getMetadata(static::FILE_METADATA_PLUGIN_ID, 'exif_orientation'))
->setFrames($file_md
->getMetadata(static::FILE_METADATA_PLUGIN_ID, 'frames_count'));
$this
->arguments()
->setSourceFormat($format);
// Only Imagemagick allows to get colorspace and profiles information
// via 'identify'.
if ($this
->getExecManager()
->getPackage() === 'imagemagick') {
$this
->setColorspace($file_md
->getMetadata(static::FILE_METADATA_PLUGIN_ID, 'colorspace'));
$this
->setProfiles($file_md
->getMetadata(static::FILE_METADATA_PLUGIN_ID, 'profiles'));
}
return TRUE;
}
return FALSE;
}