Skip to content

Technical Design: Images metadata processing

Sergii Ivashchenko edited this page Jun 10, 2020 · 9 revisions

Module

Magento\MediaGalleryMetadata module should be responsible for images metadata processing

Functionality

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.

API

image

Two API service and one data interfaces should be introduced in the Magento\MediaGalleryMetadataApi module and implemented in Magento\MediaGalleryMetadata module.

Data:

  • MetadataInterface extending Magento\Framework\Api\ExtensibleDataInterface
    • getKeywords(): array
    • getTitle(): string
    • getDescription(): string

Services:

  • GetMetadataInterace::execute(string $content): MetadataInterface retrieve the metadata from the file content
  • SaveMetadataInterace::execute(string $path, MetadataInterface $metadata): void update the metadata of the file

Exceptions

LocalizedException should be thrown if the metadata cannot be retrieved or saved

Implementation

The metadata reading/writing should work with the IIM/IPTC, XMP and EXIF file segments.

Retrieving Metadata

The metadata should be retrieved from the file segments in the following fallback order (the next segment should be used if all values cannot be found in the previous segment)

  • IIM/IPTC
  • XMP
  • EXIF

To achieve that a ReaderComposite class should be introduced implementing the internal ReadMetadataInterface::execute(string $content): MetadataInterface

The readers for each segment should be added to the ReaderPool class using DI configuration:

  • ReadIptcData class
  • ReadXmpData class
  • ReadExifData class

Each reader should return all the metadata retrieved from the segment in an array format and should implement the internal ReadMetadataInterface::execute(string $content): array

The ReaderPool class should extract the values require for the MetadataInterface from the reader's response and call the next reader only if the required values were missing in the previous reader response.

The sequence of readers should be configured by the keys of DI configuration:

<type name="Magento\MediaGalleryMetadata\Model\ReaderPool">
    <arguments>
        <argument name="readers" xsi:type="array">
            <item name="10" xsi:type="object">Magento\MediaGalleryMetadata\Model\Reader\Iptc</item>
            <item name="20" xsi:type="object">Magento\MediaGalleryMetadata\Model\Reader\Xmp</item>
            <item name="30" xsi:type="object">Magento\MediaGalleryMetadata\Model\Reader\Exif</item>
        </argument>
    </arguments>
</type>

Saving Metadata

Integration

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 frontend
  • MediaGalleryIntegration module to populate the fields of images uploaded outside of media gallery
Clone this wiki locally