public function ImagemagickToolkit::parseFile in ImageMagick 8.3
Same name and namespace in other branches
- 8 src/Plugin/ImageToolkit/ImagemagickToolkit.php \Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit::parseFile()
- 8.2 src/Plugin/ImageToolkit/ImagemagickToolkit.php \Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit::parseFile()
Determines if a file contains a valid image.
Drupal supports GIF, JPG and PNG file formats when used with the GD toolkit, and may support others, depending on which toolkits are installed.
Return value
bool TRUE if the file could be found and is an image, FALSE otherwise.
Overrides ImageToolkitInterface::parseFile
File
- src/
Plugin/ ImageToolkit/ ImagemagickToolkit.php, line 734
Class
- ImagemagickToolkit
- Provides ImageMagick integration toolkit for image manipulation.
Namespace
Drupal\imagemagick\Plugin\ImageToolkitCode
public function parseFile() {
// 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;
}