Skip to content

Commit

Permalink
fix: Fix webp error
Browse files Browse the repository at this point in the history
  • Loading branch information
kpitn committed Feb 12, 2024
1 parent 3972004 commit f71a119
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Model/Resize.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ protected function convertPngToJpg(): void
*/
protected function resizeAndSaveImage(): bool
{
if ($this->config->convertPngImage()) {
if ($this->config->convertPngImage() && $this->getFormat() !== self::FORMAT_WEBP) {
if (!$this->mediaDirectoryRead->isFile($this->absolutePathoriginal)) {
return false;
}
Expand Down
16 changes: 15 additions & 1 deletion Model/WebpConvertor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Asset\File\NotFoundException;
use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface;
use Web200\ImageResize\Provider\Config;
use WebPConvert\Convert\Exceptions\ConversionFailedException;
use WebPConvert\WebPConvert;
use Exception;

/**
* Class Convertor
Expand Down Expand Up @@ -43,22 +45,31 @@ class WebpConvertor
* @var StoreManagerInterface $storeManager
*/
protected $storeManager;
/**
* Logger
*
* @var LoggerInterface $logger
*/
protected $logger;

/**
* WebpConvertor constructor.
*
* @param Config $config
* @param StoreManagerInterface $storeManager
* @param Filesystem $filesystem
* @param LoggerInterface $logger
*/
public function __construct(
Config $config,
StoreManagerInterface $storeManager,
Filesystem $filesystem
Filesystem $filesystem,
LoggerInterface $logger
) {
$this->config = $config;
$this->mediaDirectoryRead = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
$this->storeManager = $storeManager;
$this->logger = $logger;
}

/**
Expand All @@ -83,6 +94,9 @@ public function convert(string $image): string
return $webImage;
} catch (ConversionFailedException $exception) {
return '';
} catch (Exception $exception) {
$this->logger->error('Unable to resize Image : ' . $image);
return '';
}
}

Expand Down

0 comments on commit f71a119

Please sign in to comment.