-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1570 from Nazar65/ASI-IPTC-ABJUSTMENTS
Add support for writing new IPTC segments for jpeg format and new XMP segments for PNG and GIF images formats
- Loading branch information
Showing
15 changed files
with
758 additions
and
79 deletions.
There are no files selected for viewing
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
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
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,76 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MediaGalleryMetadata\Model\Gif; | ||
|
||
use Magento\Framework\Exception\FileSystemException; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Filesystem\DriverInterface; | ||
use Magento\MediaGalleryMetadataApi\Model\FileInterface; | ||
use Magento\MediaGalleryMetadataApi\Model\FileWriterInterface; | ||
use Magento\MediaGalleryMetadataApi\Model\SegmentInterface; | ||
use Magento\MediaGalleryMetadata\Model\SegmentNames; | ||
|
||
/** | ||
* File segments writer | ||
*/ | ||
class FileWriter implements FileWriterInterface | ||
{ | ||
/** | ||
* @var DriverInterface | ||
*/ | ||
private $driver; | ||
|
||
/** | ||
* @var SegmentNames | ||
*/ | ||
private $segmentNames; | ||
|
||
/** | ||
* @param DriverInterface $driver | ||
* @param SegmentNames $segmentNames | ||
*/ | ||
public function __construct( | ||
DriverInterface $driver, | ||
SegmentNames $segmentNames | ||
) { | ||
$this->driver = $driver; | ||
$this->segmentNames = $segmentNames; | ||
} | ||
|
||
/** | ||
* Write file object to the filesystem | ||
* | ||
* @param FileInterface $file | ||
* @throws LocalizedException | ||
* @throws FileSystemException | ||
*/ | ||
public function execute(FileInterface $file): void | ||
{ | ||
$resource = $this->driver->fileOpen($file->getPath(), 'wb'); | ||
|
||
$this->writeSegments($resource, $file->getSegments()); | ||
$this->driver->fileClose($resource); | ||
} | ||
|
||
/** | ||
* Write gif segment | ||
* | ||
* @param resource $resource | ||
* @param SegmentInterface[] $segments | ||
*/ | ||
private function writeSegments($resource, array $segments): void | ||
{ | ||
foreach ($segments as $segment) { | ||
$this->driver->fileWrite( | ||
$resource, | ||
$segment->getData() | ||
); | ||
} | ||
$this->driver->fileWrite($resource, pack("C", ord(";"))); | ||
} | ||
} |
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
Oops, something went wrong.