From 1cda89fe2bf2f6e9afc7c5c8d777e10154d77b08 Mon Sep 17 00:00:00 2001 From: Christian Vette Date: Sun, 13 May 2018 02:27:50 +0200 Subject: [PATCH] FEATURE: Remove Image Id from Preview Images --- .../Shutterstock/ShutterstockAssetProxy.php | 36 +++++++++++++++++++ .../Shutterstock/ShutterstockAssetSource.php | 25 +++++++++++++ 2 files changed, 61 insertions(+) diff --git a/Classes/Domain/Model/AssetSource/Shutterstock/ShutterstockAssetProxy.php b/Classes/Domain/Model/AssetSource/Shutterstock/ShutterstockAssetProxy.php index 8172d44..0d367de 100644 --- a/Classes/Domain/Model/AssetSource/Shutterstock/ShutterstockAssetProxy.php +++ b/Classes/Domain/Model/AssetSource/Shutterstock/ShutterstockAssetProxy.php @@ -1,6 +1,9 @@ assetSource->isRemoveImageIdFromPreview()) { + return $this->removeImageId(); + } + return fopen($this->shutterstockData['assets']['preview']['url'], 'r'); } + /** + * Crops the image preview so the image Id is not shown + * + * @return bool|resource + */ + protected function removeImageId() + { + $fileHandle = fopen($this->shutterstockData['assets']['preview']['url'], 'r'); + $image = $this->imagineService->read($fileHandle); + + $width = $this->shutterstockData['assets']['preview']['width']; + $height = $this->shutterstockData['assets']['preview']['height']; + + $image->crop(new Point(0,0), new Box($width, $height)); + $string = $image->get('jpg'); + + $stream = fopen('php://memory','r+'); + fwrite($stream, $string); + rewind($stream); + + return $stream; + } + public function getLocalAssetIdentifier(): ?string { return $this->importedAsset instanceof ImportedAsset ? $this->importedAsset->getLocalAssetIdentifier() : ''; diff --git a/Classes/Domain/Model/AssetSource/Shutterstock/ShutterstockAssetSource.php b/Classes/Domain/Model/AssetSource/Shutterstock/ShutterstockAssetSource.php index 22d05ad..9969650 100644 --- a/Classes/Domain/Model/AssetSource/Shutterstock/ShutterstockAssetSource.php +++ b/Classes/Domain/Model/AssetSource/Shutterstock/ShutterstockAssetSource.php @@ -32,6 +32,11 @@ class ShutterstockAssetSource implements AssetSourceInterface */ protected $shutterstockClient; + /** + * @var bool + */ + protected $removeImageIdFromPreview = true; + /** * ShutterstockAssetSource constructor. @@ -62,6 +67,10 @@ public function initializeObject() $this->shutterstockClient->setQueryParams($this->assetSourceOptions['queryParams']); } + if (isset($this->assetSourceOptions['removeImageIdFromPreview'])) { + $this->removeImageIdFromPreview = $this->assetSourceOptions['removeImageIdFromPreview']; + } + $this->shutterstockClient->setClientKey($this->assetSourceOptions['clientKey']); $this->shutterstockClient->setClientSecret($this->assetSourceOptions['clientSecret']); } @@ -127,4 +136,20 @@ public function isReadOnly(): bool { return true; } + + /** + * @return bool + */ + public function isRemoveImageIdFromPreview(): bool + { + return $this->removeImageIdFromPreview; + } + + /** + * @param bool $removeImageDetailsFromPreview + */ + public function setRemoveImageIdFromPreview(bool $removeImageIdFromPreview): void + { + $this->removeImageIdFromPreview = $removeImageIdFromPreview; + } }