Magento2 Visual Swatch : transparent image black background
-
01-01-2021 - |
解決
I resolved by following
etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Swatches\Helper\Media" type="Vendor\Module\Helper\Media" />
</config>
Helper/Media.php
<?php
namespace Vendor\Module\Helper;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\Area;
use Magento\Catalog\Helper\Image;
class Media extends \Magento\Swatches\Helper\Media
{
protected function setupImageProperties(\Magento\Framework\Image $image, $isSwatch = false)
{
$image->quality(100);
$image->constrainOnly(true);
$image->keepAspectRatio(true);
$image->keepTransparency(true);
if ($isSwatch) {
$image->keepFrame(true);
}
return $this;
}
}
Rest of the module files you've to create by yourself.
所属していません magento.stackexchange