102 \Psr\Log\LoggerInterface
$logger,
103 array
$imageParams = [self::PREVIEW_IMAGE_WIDTH, self::PREVIEW_IMAGE_HEIGHT],
127 $image = $this->imageFactory->create($imagePath);
128 $image->keepTransparency(
true);
129 $image->constrainOnly(
true);
131 $image->keepAspectRatio(
true);
132 $image->backgroundColor([255, 255, 255]);
133 $image->resize($imageWidth, $imageHeight);
135 $imageName = uniqid(
'preview_image_') . image_type_to_extension(
$image->getImageType());
136 $image->save($this->themeImagePath->getImagePreviewDirectory(), $imageName);
137 $this->theme->setPreviewImage($imageName);
149 $previewDir = $this->themeImagePath->getImagePreviewDirectory();
150 $sourcePath =
$theme->getThemeImage()->getPreviewImagePath();
151 $sourceRelativePath = $this->rootDirectory->getRelativePath($sourcePath);
152 if (!
$theme->getPreviewImage() && !$this->mediaDirectory->isExist($sourceRelativePath)) {
158 $targetRelativePath = $this->mediaDirectory->getRelativePath($previewDir .
'/' . $destinationFileName);
159 $isCopied = $this->rootDirectory->copyFile($sourceRelativePath, $targetRelativePath, $this->mediaDirectory);
160 $this->theme->setPreviewImage($destinationFileName);
162 $this->theme->setPreviewImage(
null);
163 $this->logger->critical($e);
175 $previewImage = $this->theme->getPreviewImage();
176 $this->theme->setPreviewImage(
null);
178 $previewImagePath = $this->themeImagePath->getImagePreviewDirectory() .
'/' . $previewImage;
179 return $this->mediaDirectory->delete($this->mediaDirectory->getRelativePath($previewImagePath));
192 $tmpDirPath = $this->themeImagePath->getTemporaryDirectory();
193 $tmpFilePath = $this->uploader->uploadPreviewImage($scope, $tmpDirPath);
195 if ($this->theme->getPreviewImage()) {
199 $this->mediaDirectory->delete($tmpFilePath);
211 return $this->themeImagePath->getPreviewImagePath($this->theme);
221 $previewImage = $this->theme->getPreviewImage();
222 return empty($previewImage)
223 ? $this->themeImagePath->getPreviewImageDefaultUrl()
224 : $this->themeImagePath->getPreviewImageUrl($this->theme);
createPreviewImage($imagePath)
createPreviewImageCopy(ThemeInterface $theme)
uploadPreviewImage($scope)
__construct(\Magento\Framework\Filesystem $filesystem, \Magento\Framework\Image\Factory $imageFactory, Image\Uploader $uploader, Image\PathInterface $themeImagePath, \Psr\Log\LoggerInterface $logger, array $imageParams=[self::PREVIEW_IMAGE_WIDTH, self::PREVIEW_IMAGE_HEIGHT], ThemeInterface $theme=null)
const PREVIEW_IMAGE_WIDTH
static getNewFileName($destinationFile)
const PREVIEW_IMAGE_HEIGHT