Same name in other branches
- 8.x-1.x src/ExifContent.php \Drupal\exif\ExifContent::getDataFromFileUri()
Retrieve all metadata values from an image.
Paramètres
\Drupal\Core\Field\Plugin\Field\FieldType\UriItem $file_uri: The File URI to look at.
Return value
array A map of metadata values by key.
1 call to ExifContent::getDataFromFileUri()
- ExifContent::getImageFieldsMetadata dans src/
ExifContent.php - List fields that contains exif metadata.
Fichier
-
src/
ExifContent.php, line 383
Classe
- ExifContent
- Class ExifContent make link between drupal content and file content.
Namespace
Drupal\exifCode
private function getDataFromFileUri(UriItem $file_uri) {
$uri = $file_uri->getValue()['value'];
$scheme = \Drupal::service('stream_wrapper_manager')->getScheme($uri);
// If the file isn't stored locally make a temporary copy to read the
// metadata from. We just assume that the temporary files are always local,
// hard to figure out how to handle this otherwise.
if (!isset(\Drupal::service('stream_wrapper_manager')->getWrappers(StreamWrapperInterface::LOCAL)[$scheme])) {
// Local stream.
$cache_key = md5($uri);
if (empty($this->localCopiesOfRemoteFiles[$cache_key])) {
// Create unique local file.
if (!($this->localCopiesOfRemoteFiles[$cache_key] = \Drupal::service('file_system')->copy($uri, 'temporary://exif_' . $cache_key . '_' . basename($uri), FileSystemInterface::EXISTS_REPLACE))) {
// Log error if creating a copy fails - but return an empty array to
// avoid type collision.
\Drupal::logger('exif')->notice('Unable to create local temporary copy of remote file for exif extraction! File %file.', [
'%file' => $uri,
]);
return [];
}
}
$uri = $this->localCopiesOfRemoteFiles[$cache_key];
}
// Read the metadata.
$exif = ExifFactory::getExifInterface();
/** @var \Drupal\Core\File\FileSystem $file_system */
$file_system = \Drupal::service('file_system');
$fullmetadata = $exif->readMetadataTags($file_system->realpath($uri));
return $fullmetadata;
}