-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
app/code/Magento/MediaGalleryMetadata/Model/Jpeg/Segment/ReadExif.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MediaGalleryMetadata\Model\Jpeg\Segment; | ||
|
||
use Magento\MediaGalleryMetadataApi\Api\Data\MetadataInterface; | ||
use Magento\MediaGalleryMetadataApi\Api\Data\MetadataInterfaceFactory; | ||
use Magento\MediaGalleryMetadataApi\Model\FileInterface; | ||
use Magento\MediaGalleryMetadataApi\Model\ReadMetadataInterface; | ||
use Magento\MediaGalleryMetadataApi\Model\SegmentInterface; | ||
|
||
/** | ||
* Jpeg EXIF Reader | ||
*/ | ||
class ReadExif implements ReadMetadataInterface | ||
{ | ||
private const EXIF_SEGMENT_NAME = 'APP1'; | ||
private const EXIF_SEGMENT_START = "Exif\x00"; | ||
private const EXIF_DATA_START_POSITION = 0; | ||
|
||
/** | ||
* @var MetadataInterfaceFactory | ||
*/ | ||
private $metadataFactory; | ||
|
||
/** | ||
* @param MetadataInterfaceFactory $metadataFactory | ||
*/ | ||
public function __construct( | ||
MetadataInterfaceFactory $metadataFactory | ||
) { | ||
$this->metadataFactory = $metadataFactory; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(FileInterface $file): MetadataInterface | ||
{ | ||
$title = null; | ||
$description = null; | ||
$keywords = []; | ||
|
||
foreach ($file->getSegments() as $segment) { | ||
if ($this->isExifSegment($segment)) { | ||
} | ||
} | ||
return $this->metadataFactory->create([ | ||
'title' => $title, | ||
'description' => $description, | ||
'keywords' => !empty($keywords) ? $keywords : null | ||
]); | ||
} | ||
|
||
/** | ||
* Does segment contain Exif data | ||
* | ||
* @param SegmentInterface $segment | ||
* @return bool | ||
*/ | ||
private function isExifSegment(SegmentInterface $segment): bool | ||
{ | ||
return $segment->getName() === self::EXIF_SEGMENT_NAME | ||
&& strncmp( | ||
substr($segment->getData(), self::EXIF_DATA_START_POSITION, 4), | ||
self::EXIF_SEGMENT_START, | ||
self::EXIF_DATA_START_POSITION | ||
) == 0; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters