media_image_metadata
This module extracts metadata from image files and maps them to media fields.
Any metadata embedded in images according to the standards:
can be retrieved by this module.
A mapping is provided to make it easier to access the most commonly-used attributes without having to know exactly the code/address of the data in the different standards.
Metadata Attributes Provided
The above table shows the prioritization order for each metadata attribute. For example, when looking for the caption metadata attribute, the module will first look at the 2#120 value (in IPTC data), and if this is empty, it will fall back to dc:description (in XMP data), and finally to ImageDescription (in EXIF data).
Note:
The title attribute will fall back to the filename, if none of the above sources returned a non-empty value.
Retrieving unmapped metadata from images
If your images have metadata embedded in different locations, you can easily alter the above mapping by implementing the hook_media_image_metadata_alter() hook in a custom module, like so:
function foo_media_image_metadata_alter(array &$normalized_metadata, array $raw_metadata) {
// Use IPTC "Special Instruction" as caption.
if (!empty($raw_metadata['iptc']['2#40'])) {
$normalized_metadata['caption'] = $raw_metadata['iptc']['2#40'];
}
}
Requirements
- Media module (from core)
- (Optional) PHP 8.2+ with EXIF extension (only if you need EXIF metadata)