Skip to content
17 changes: 13 additions & 4 deletions app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @api
* @since 100.0.2
Expand Down Expand Up @@ -152,6 +153,11 @@ class Storage extends \Magento\Framework\DataObject
*/
private $ioFile;

/**
* @var \Magento\Framework\File\Mime|null
*/
private $mime;

/**
* Construct
*
Expand All @@ -173,6 +179,7 @@ class Storage extends \Magento\Framework\DataObject
* @param array $data
* @param \Magento\Framework\Filesystem\DriverInterface $file
* @param \Magento\Framework\Filesystem\Io\File|null $ioFile
* @param \Magento\Framework\File\Mime $mime
* @param \Psr\Log\LoggerInterface|null $logger
*
* @throws \Magento\Framework\Exception\FileSystemException
Expand All @@ -197,6 +204,7 @@ public function __construct(
array $data = [],
\Magento\Framework\Filesystem\DriverInterface $file = null,
\Magento\Framework\Filesystem\Io\File $ioFile = null,
\Magento\Framework\File\Mime $mime = null,
\Psr\Log\LoggerInterface $logger = null
) {
$this->_session = $session;
Expand All @@ -217,6 +225,7 @@ public function __construct(
$this->_dirs = $dirs;
$this->file = $file ?: ObjectManager::getInstance()->get(\Magento\Framework\Filesystem\Driver\File::class);
$this->ioFile = $ioFile ?: ObjectManager::getInstance()->get(\Magento\Framework\Filesystem\Io\File::class);
$this->mime = $mime ?: ObjectManager::getInstance()->get(\Magento\Framework\File\Mime::class);
parent::__construct($data);
}

Expand Down Expand Up @@ -362,7 +371,7 @@ public function getFilesCollection($path, $type = null)
$item->setUrl($this->_cmsWysiwygImages->getCurrentUrl() . $item->getBasename());
$itemStats = $this->file->stat($item->getFilename());
$item->setSize($itemStats['size']);
$item->setMimeType(\mime_content_type($item->getFilename()));
$item->setMimeType($this->mime->getMimeType($item->getFilename()));

if ($this->isImage($item->getBasename())) {
$thumbUrl = $this->getThumbnailUrl($item->getFilename(), true);
Expand Down Expand Up @@ -647,7 +656,7 @@ public function resizeFile($source, $keepRatio = true)
$image->keepAspectRatio($keepRatio);

list($imageWidth, $imageHeight) = $this->getResizedParams($source);

$image->resize($imageWidth, $imageHeight);
$dest = $targetDir . '/' . $this->ioFile->getPathInfo($source)['basename'];
$image->save($dest);
Expand All @@ -670,7 +679,7 @@ private function getResizedParams(string $source): array

//phpcs:ignore Generic.PHP.NoSilencedErrors
list($imageWidth, $imageHeight) = @getimagesize($source);

if ($imageWidth && $imageHeight) {
$imageWidth = $configWidth > $imageWidth ? $imageWidth : $configWidth;
$imageHeight = $configHeight > $imageHeight ? $imageHeight : $configHeight;
Expand All @@ -679,7 +688,7 @@ private function getResizedParams(string $source): array
}
return [$configWidth, $configHeight];
}

/**
* Resize images on the fly in controller action
*
Expand Down