-
Notifications
You must be signed in to change notification settings - Fork 90
Technical Design: Images metadata processing
Magento\MediaGalleryMetadata module should be responsible for images metadata processing
MediaGalleryMetadata module should provide an ability to extract the metadata from file and populating Media Asset entity fields when an image is uploaded to Magento.
MediaGalleryMetadata module should provide an ability to update the metadata stored in an image file.

Two API service and one data interfaces should be introduced in the Magento\MediaGalleryMetadataApi module and implemented in Magento\MediaGalleryMetadata module.
Data:
-
MetadataInterfaceextendingMagento\Framework\Api\ExtensibleDataInterfacegetTitle(): stringgetDescription(): stringgetKeywords(): array
Services:
-
ExtractMetadataInterace::execute(string $path): MetadataInterfaceretrieve the metadata from the file -
AddMetadataInterace::execute(string $path, MetadataInterface $metadata): voidupdate the metadata in the file
ExtractMetadataInterace does not throw any exceptions, empty metadata object is returned if metadata cannot be retrieved
LocalizedException should be thrown by AddMetadataInterace if the metadata cannot be retrieved or saved
Magento media gallery supports jpeg, gif and png formats
- JPEG images can have the metadata saved in EXIF, XMP and IPTC formats.
- PNG images can have the metadata saved in EXIF, XMP and IPTC formats.
- GIF images can have the metadata saved only in XMP format.
The metadata reading/writing should work with the IPTC, XMP and EXIF file segments.
The process of retrieving metadata from a file includes the following stages:
-
Extract Metadata Serviceis running through all available metadataExtractorsfrom theExtractors Pool - Each
Extractoris checking with it'sFile Readerif it can read the file - If the file can be read, the
File Readeris parsing the file intoSegment Objectswrapping them intoFile Object -
Extractorthen sends theFile Objectto all the available to this extractorSegment Readers - Each
Segment Readeris:- Retrieving appropriate
Segment ObjectfromFile Object - Extracting metadata from
Segment Objectdata and returning it as aMetadata Object
- Retrieving appropriate
-
Extractoraccumulates the data received from theSegment Readersand as soon as all needed metadata fields are populated returns theMetadata Object -
Extract Metadata Serviceis accumulating the data received from theExtractorsand as soon as all needed metadata fields are populated returns theMetadata Object

Terms:
- "Extract Metadata Service" -
Magento\MediaGalleryMetadata\Model\ExtractMetadata - "Extractors Pool" -
Magento\MediaGalleryMetadataApi\Model\ExtractMetadataPool - "Extractor" - virtual type based on the
Magento\MediaGalleryMetadata\Model\File\ExtractMetadata - "File Reader" -
Magento\MediaGalleryMetadataApi\Model\FileReaderInterface - "Segment Reader" -
Magento\MediaGalleryMetadataApi\Model\MetadataReaderInterface - "File Object" -
Magento\MediaGalleryMetadataApi\Model\FileInterface - "Segment Object" -
Magento\MediaGalleryMetadataApi\Model\SegmentInterface - "Metadata Object" -
Magento\MediaGalleryMetadataApi\Api\Data\MetadataInterface
The Extractor can be created as a virtual type based on Magento\MediaGalleryMetadata\Model\File\ExtractMetadata class specifying the file reader and segment readers.
The Extractor can be added to the Extractors Pool using DI configuration.
The process of retrieving metadata from a file includes the following stages:
-
Add Metadata Serviceis running through all availableMetadata Updatersfrom theMetadata Updaters Pool - Each
Metadata Updateris retrieving theFile ObjectusingFile Reader - Then
Metadata Updateris calling all theSegment Writerspassing theFile ObjectandMetadata Object -
Segment Writersare adding the data fromMetadata Objectto the corresponding segment in theFile Objectand return the updated object - After all the
Segment Writersare done, theFile Objectis saved to the filesystem by theFile Writer
Terms:
- "Add Metadata Service" -
Magento\MediaGalleryMetadata\Model\AddMetadata - "Metadata Updaters Pool" -
Magento\MediaGalleryMetadataApi\Model\AddMetadataPool - "Metadata Updater" - virtual type based on the
Magento\MediaGalleryMetadata\Model\File\AddMetadata - "File Writer" -
Magento\MediaGalleryMetadataApi\Model\FileWriterInterface - "Segment Writer" -
Magento\MediaGalleryMetadataApi\Model\MetadataWriterInterface
The Metadata Updater can be created as a virtual type based on Magento\MediaGalleryMetadata\Model\File\AddMetadata class specifying the file reader, file writer and segment writers.
The Metadata Updater can be added to the Metadata Updaters Pool using DI configuration.
MediaGalleryMetadata should be used in:
- MediaGallerySynchronization module to populate the fields of synchronized images
- MediaGalleryUi module
- to populate the fields of images uploaded from the media gallery
- to update metadata in the image file when the metadata is edited on the frontend
- MediaGalleryIntegration module to populate the fields of images uploaded outside of media gallery