Skip to content

Commit

Permalink
Improve metadata types && isExifSegment() verification for jpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
Nazar65 committed Aug 17, 2020
1 parent bed58c5 commit 58fbad4
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use Magento\MediaGalleryMetadataApi\Api\Data\MetadataInterface;
use Magento\MediaGalleryMetadataApi\Api\Data\MetadataInterfaceFactory;
use Magento\MediaGalleryMetadataApi\Model\SegmentInterface;

/**
* Get metadata from IPTC block
Expand Down Expand Up @@ -42,8 +41,8 @@ public function __construct(
*/
public function execute(string $data): MetadataInterface
{
$title = '';
$description = '';
$title = null;
$description = null;
$keywords = [];

if (is_callable('iptcparse')) {
Expand All @@ -65,7 +64,7 @@ public function execute(string $data): MetadataInterface
return $this->metadataFactory->create([
'title' => $title,
'description' => $description,
'keywords' => $keywords
'keywords' => !empty($keywords) ? $keywords : null
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,19 @@ private function getExifData(string $filePath): MetadataInterface
{
$title = null;
$description = null;
$keywords = [];
$keywords = null;

$data = exif_read_data($filePath);

if ($data) {
if (!empty($data)) {
$title = isset($data['DocumentName']) ? $data['DocumentName'] : null;
$description = isset($data['ImageDescription']) ? $data['ImageDescription'] : null;
$keywords = '';
}

return $this->metadataFactory->create([
'title' => $title,
'description' => $description,
'keywords' => !empty($keywords) ? $keywords : null
'keywords' => $keywords
]);
}

Expand All @@ -97,9 +96,9 @@ private function isExifSegment(SegmentInterface $segment): bool
{
return $segment->getName() === self::EXIF_SEGMENT_NAME
&& strncmp(
substr($segment->getData(), self::EXIF_DATA_START_POSITION, 4),
substr($segment->getData(), self::EXIF_DATA_START_POSITION, 5),
self::EXIF_SEGMENT_START,
self::EXIF_DATA_START_POSITION
5
) == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public function execute(FileInterface $file): MetadataInterface
}
}
return $this->metadataFactory->create([
'title' => '',
'description' => '',
'keywords' => []
'title' => null,
'description' => null,
'keywords' => null
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function execute(FileInterface $file): MetadataInterface
}
}
return $this->metadataFactory->create([
'title' => '',
'description' => '',
'keywords' => []
'title' => null,
'description' => null,
'keywords' => null
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ private function getExifData(SegmentInterface $segment): MetadataInterface
if ($data) {
$title = isset($data['DocumentName']) ? $data['DocumentName'] : null;
$description = isset($data['ImageDescription']) ? $data['ImageDescription'] : null;
$keywords = '';
}

return $this->metadataFactory->create([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public function execute(FileInterface $file): MetadataInterface
}
}
return $this->metadataFactory->create([
'title' => '',
'description' => '',
'keywords' => []
'title' => null,
'description' => null,
'keywords' => null
]);
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 58fbad4

Please sign in to comment.