protected function Exif::doGetMetadataFromFile in File metadata manager 8
Same name and namespace in other branches
- 8.2 file_mdm_exif/src/Plugin/FileMetadata/Exif.php \Drupal\file_mdm_exif\Plugin\FileMetadata\Exif::doGetMetadataFromFile()
Gets file metadata from the file at URI/local path.
Return value
mixed The metadata retrieved from the file.
Throws
\Drupal\file_mdm\FileMetadataException In case there were significant errors reading from file.
Overrides FileMetadataPluginBase::doGetMetadataFromFile
File
- file_mdm_exif/
src/ Plugin/ FileMetadata/ Exif.php, line 125
Class
- Exif
- FileMetadata plugin for EXIF.
Namespace
Drupal\file_mdm_exif\Plugin\FileMetadataCode
protected function doGetMetadataFromFile() {
// Get the file as a PelJpeg or PelTiff object.
$file = $this
->getFile();
if (!$file) {
return [];
}
// Get the TIFF section if existing, or return if not.
if ($file instanceof PelJpeg) {
$exif = $file
->getExif();
if ($exif === NULL) {
return [];
}
$tiff = $exif
->getTiff();
if ($tiff === NULL) {
return [];
}
}
elseif ($file instanceof PelTiff) {
$tiff = $file;
}
// Scans metadata for entries of supported tags.
$metadata = [];
$keys = $this->tagMapper
->getSupportedKeys();
foreach ($keys as $key) {
$ifd_tag = $this->tagMapper
->resolveKeyToIfdAndTag($key);
if ($entry = $this
->getEntry($tiff, $ifd_tag['ifd'], $ifd_tag['tag'])) {
$metadata[$ifd_tag['ifd']][$ifd_tag['tag']] = $entry;
}
}
return $metadata;
}