Skip to content

Commit c982412

Browse files
ENGCOM-8005: Fix new iTxt && zTxt segment creation for PNG image XMP && IPTC segments #29475
- Merge Pull Request #29475 from Nazar65/magento2:ASI-1743 - Merged commits: 1. bb1ba14 2. a156298 3. f7e9830 4. dd9a41f 5. f165c8f 6. e0f3252 7. f3d831d 8. a9fda1e
2 parents 7198c76 + a9fda1e commit c982412

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

app/code/Magento/MediaGalleryMetadata/Model/Png/Segment/WriteIptc.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ public function execute(FileInterface $file, MetadataInterface $metadata): FileI
7171
}
7272

7373
if (empty($pngIptcSegments)) {
74-
$segments[] = $this->createPngIptcSegment($metadata);
75-
7674
return $this->fileFactory->create([
7775
'path' => $file->getPath(),
78-
'segments' => $segments
76+
'segments' => $this->insertPngIptcSegment($segments, $this->createPngIptcSegment($metadata))
7977
]);
8078
}
8179

@@ -89,6 +87,24 @@ public function execute(FileInterface $file, MetadataInterface $metadata): FileI
8987
]);
9088
}
9189

90+
/**
91+
* Insert IPTC segment to image png segments before IEND chunk
92+
*
93+
* @param SegmentInterface[] $segments
94+
* @param SegmentInterface $iptcSegment
95+
* @return SegmentInterface[]
96+
*/
97+
private function insertPngIptcSegment(array $segments, SegmentInterface $iptcSegment): array
98+
{
99+
$iendSegmentIndex = count($segments) - 1;
100+
101+
return array_merge(
102+
array_slice($segments, 0, $iendSegmentIndex),
103+
[$iptcSegment],
104+
array_slice($segments, $iendSegmentIndex)
105+
);
106+
}
107+
92108
/**
93109
* Create new zTXt segment with metadata
94110
*

app/code/Magento/MediaGalleryMetadata/Model/Png/Segment/WriteXmp.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,20 @@ public function execute(FileInterface $file, MetadataInterface $metadata): FileI
9797
}
9898

9999
/**
100-
* Insert XMP segment to image png segments (at position 1)
100+
* Insert XMP segment to image png segments before IEND chunk
101101
*
102102
* @param SegmentInterface[] $segments
103103
* @param SegmentInterface $xmpSegment
104104
* @return SegmentInterface[]
105105
*/
106106
private function insertPngXmpSegment(array $segments, SegmentInterface $xmpSegment): array
107107
{
108-
return array_merge(array_slice($segments, 0, 2), [$xmpSegment], array_slice($segments, 2));
108+
$iendSegmentIndex = count($segments) - 1;
109+
return array_merge(
110+
array_slice($segments, 0, $iendSegmentIndex),
111+
[$xmpSegment],
112+
array_slice($segments, $iendSegmentIndex)
113+
);
109114
}
110115

111116
/**

0 commit comments

Comments
 (0)