Skip to content

Commit

Permalink
ENGCOM-8005: Fix new iTxt && zTxt segment creation for PNG image XMP …
Browse files Browse the repository at this point in the history
…&& 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
  • Loading branch information
magento-engcom-team committed Aug 14, 2020
2 parents 7198c76 + a9fda1e commit c982412
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ public function execute(FileInterface $file, MetadataInterface $metadata): FileI
}

if (empty($pngIptcSegments)) {
$segments[] = $this->createPngIptcSegment($metadata);

return $this->fileFactory->create([
'path' => $file->getPath(),
'segments' => $segments
'segments' => $this->insertPngIptcSegment($segments, $this->createPngIptcSegment($metadata))
]);
}

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

/**
* Insert IPTC segment to image png segments before IEND chunk
*
* @param SegmentInterface[] $segments
* @param SegmentInterface $iptcSegment
* @return SegmentInterface[]
*/
private function insertPngIptcSegment(array $segments, SegmentInterface $iptcSegment): array
{
$iendSegmentIndex = count($segments) - 1;

return array_merge(
array_slice($segments, 0, $iendSegmentIndex),
[$iptcSegment],
array_slice($segments, $iendSegmentIndex)
);
}

/**
* Create new zTXt segment with metadata
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,20 @@ public function execute(FileInterface $file, MetadataInterface $metadata): FileI
}

/**
* Insert XMP segment to image png segments (at position 1)
* Insert XMP segment to image png segments before IEND chunk
*
* @param SegmentInterface[] $segments
* @param SegmentInterface $xmpSegment
* @return SegmentInterface[]
*/
private function insertPngXmpSegment(array $segments, SegmentInterface $xmpSegment): array
{
return array_merge(array_slice($segments, 0, 2), [$xmpSegment], array_slice($segments, 2));
$iendSegmentIndex = count($segments) - 1;
return array_merge(
array_slice($segments, 0, $iendSegmentIndex),
[$xmpSegment],
array_slice($segments, $iendSegmentIndex)
);
}

/**
Expand Down

0 comments on commit c982412

Please sign in to comment.