Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spike] Investigate meta data extracting #1237

Closed
lenaorobei opened this issue Apr 20, 2020 · 2 comments · Fixed by #1514
Closed

[Spike] Investigate meta data extracting #1237

lenaorobei opened this issue Apr 20, 2020 · 2 comments · Fixed by #1514
Assignees
Labels
Priority: P1 Needs to be fixed before any other issues requires technical design
Milestone

Comments

@lenaorobei
Copy link
Contributor

lenaorobei commented Apr 20, 2020

As a Merchant I want Magento Media Storage to parse image meta data that is available in the file and expose it on image details page so that I can manage it and use for filtering images

Additional context
#1183

Open questions:

  • is there any required set of fields that exist in image meta data? Like title, description, keywords. Or any fields can be removed/added to the file according to standard?
  • is there a way in a meta data file to define what fields can be edited by user in the application? e.g. Camera data, image format, creation and modification date can not be edited
@sivaschenko sivaschenko added this to the 1.2.0 milestone Apr 25, 2020
@sivaschenko
Copy link
Member

Neet to try exif_read_data on different image formats

@sivaschenko sivaschenko added the Priority: P1 Needs to be fixed before any other issues label Jun 5, 2020
@sivaschenko
Copy link
Member

sivaschenko commented Jun 8, 2020

We can use the APP13 IPTC data of the image for reading and saving metadata.

Reading the metadata:

$iptcHeaders = [
    'title' => '2#005',
    'headline' => '2#105',
    'keywords' => '2#025'
];

getimagesize('image.jpg', $info);
$decodedMetadata = iptcparse($info['APP13']);
$keywords = $decodedMetadata[$iptcHeaders['keywords']];
$title = $decodedMetadata[$iptcHeaders['headline']];

Saving the metadata:

$newTitle = 'New Title';
$length = strlen($newTitle);
$retval = chr(0x1C) . chr(2) . chr(substr($iptcHeaders['headline'], 2));
if($length < 0x8000) {
    $retval .= chr($length >> 8) .  chr($length & 0xFF);
} else {
    $retval .= chr(0x80) .
        chr(0x04) .
        chr(($length >> 24) & 0xFF) .
        chr(($length >> 16) & 0xFF) .
        chr(($length >> 8) & 0xFF) .
        chr($length & 0xFF);
}
$data = $retval . $newTitle;

$content = iptcembed($data, $filename);

$file = fopen($filename, "wb");
fwrite($file, $content);
fclose($file);

IPTC standard: https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P1 Needs to be fixed before any other issues requires technical design
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants