Skip to content

Commit

Permalink
ENGCOM-4378: [Catalog] [MediaStorage] Fix watermark in media applicat…
Browse files Browse the repository at this point in the history
…ion #21338
  • Loading branch information
sivaschenko authored Mar 4, 2019
2 parents b736175 + 13b3498 commit 9a78c5e
Showing 1 changed file with 48 additions and 7 deletions.
55 changes: 48 additions & 7 deletions app/code/Magento/MediaStorage/Service/ImageResize.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Image resize service.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ImageResize
Expand Down Expand Up @@ -123,7 +125,8 @@ public function __construct(
}

/**
* Create resized images of different sizes from an original image
* Create resized images of different sizes from an original image.
*
* @param string $originalImageName
* @throws NotFoundException
*/
Expand All @@ -141,7 +144,8 @@ public function resizeFromImageName(string $originalImageName)
}

/**
* Create resized images of different sizes from themes
* Create resized images of different sizes from themes.
*
* @param array|null $themes
* @return \Generator
* @throws NotFoundException
Expand Down Expand Up @@ -169,7 +173,8 @@ public function resizeFromThemes(array $themes = null): \Generator
}

/**
* Search the current theme
* Search the current theme.
*
* @return array
*/
private function getThemesInUse(): array
Expand All @@ -187,7 +192,8 @@ private function getThemesInUse(): array
}

/**
* Get view images data from themes
* Get view images data from themes.
*
* @param array $themes
* @return array
*/
Expand All @@ -211,7 +217,8 @@ private function getViewImages(array $themes): array
}

/**
* Get unique image index
* Get unique image index.
*
* @param array $imageData
* @return string
*/
Expand All @@ -223,7 +230,8 @@ private function getUniqueImageIndex(array $imageData): string
}

/**
* Make image
* Make image.
*
* @param string $originalImagePath
* @param array $imageParams
* @return Image
Expand All @@ -241,7 +249,8 @@ private function makeImage(string $originalImagePath, array $imageParams): Image
}

/**
* Resize image
* Resize image.
*
* @param array $viewImage
* @param string $originalImagePath
* @param string $originalImageName
Expand All @@ -257,9 +266,41 @@ private function resize(array $viewImage, string $originalImagePath, string $ori
]
);

if (isset($imageParams['watermark_file'])) {
if ($imageParams['watermark_height'] !== null) {
$image->setWatermarkHeight($imageParams['watermark_height']);
}

if ($imageParams['watermark_width'] !== null) {
$image->setWatermarkWidth($imageParams['watermark_width']);
}

if ($imageParams['watermark_position'] !== null) {
$image->setWatermarkPosition($imageParams['watermark_position']);
}

if ($imageParams['watermark_image_opacity'] !== null) {
$image->setWatermarkImageOpacity($imageParams['watermark_image_opacity']);
}

$image->watermark($this->getWatermarkFilePath($imageParams['watermark_file']));
}

if ($imageParams['image_width'] !== null && $imageParams['image_height'] !== null) {
$image->resize($imageParams['image_width'], $imageParams['image_height']);
}
$image->save($imageAsset->getPath());
}

/**
* Returns watermark file absolute path
*
* @param string $file
* @return string
*/
private function getWatermarkFilePath($file)
{
$path = $this->imageConfig->getMediaPath('/watermark/' . $file);
return $this->mediaDirectory->getAbsolutePath($path);
}
}

0 comments on commit 9a78c5e

Please sign in to comment.