private function ExifContent::getDataFromFileUri in Exif 8
Same name and namespace in other branches
- 8.2 src/ExifContent.php \Drupal\exif\ExifContent::getDataFromFileUri()
Retrieve all metadata values from an image.
Parameters
\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 in src/
ExifContent.php - List fields that contains exif metadata.
File
- src/
ExifContent.php, line 372
Class
- 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'];
/** @var \Drupal\Core\File\FileSystem $file_system */
$file_system = \Drupal::service('file_system');
$scheme = $file_system
->uriScheme($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] = file_unmanaged_copy($uri, 'temporary://exif_' . $cache_key . '_' . basename($uri), FILE_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();
$fullmetadata = $exif
->readMetadataTags($file_system
->realpath($uri));
return $fullmetadata;
}