-
Notifications
You must be signed in to change notification settings - Fork 91
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:
-
MetadataInterface
extendingMagento\Framework\Api\ExtensibleDataInterface
getTitle(): string
getDescription(): string
getKeywords(): array
Services:
-
ExtractMetadataInterace::execute(string $path): MetadataInterface
retrieve the metadata from the file -
AddMetadataInterace::execute(string $path, MetadataInterface $metadata): void
update 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 Service
is running through all available metadataExtractors
from theExtractors Pool
- Each
Extractor
is checking with it'sFile Reader
if it can read the file - If the file can be read, the
File Reader
is parsing the file intoSegment Objects
wrapping them intoFile Object
-
Extractor
then sends theFile Object
to all the available to this extractorSegment Readers
- Each
Segment Reader
is:- Retrieving appropriate
Segment Object
fromFile Object
- Extracting metadata from
Segment Object
data and returning it as aMetadata Object
- Retrieving appropriate
-
Extractor
accumulates the data received from theSegment Readers
and as soon as all needed metadata fields are populated returns theMetadata Object
-
Extract Metadata Service
is accumulating the data received from theExtractors
and 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 Service
is running through all availableMetadata Updaters
from theMetadata Updaters Pool
- Each
Metadata Updater
is retrieving theFile Object
usingFile Reader
- Then
Metadata Updater
is calling all theSegment Writers
passing theFile Object
andMetadata Object
-
Segment Writers
are adding the data fromMetadata Object
to the corresponding segment in theFile Object
and return the updated object - After all the
Segment Writers
are done, theFile Object
is 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