0

enter image description here

Is anyone else having this issue, In visual swatch, I've uploaded transparent image and in frontend it showing like this? Magento ver. 2.1.3

Kaushal Suthar
  • 3,227
  • 5
  • 31
  • 57

2 Answers2

2

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.

Kaushal Suthar
  • 3,227
  • 5
  • 31
  • 57
2

You might be using a wrong bit depth with your images. Be sure to use 32-BIT or 64-BIT images, to support transparency when Magento manipulates it.

For example : if you have an image in 8-BIT, when Magento will generate the variations of it, the transparency is not kept by default for 8-BIT images, and a background will be applied to it.

There usually are options on image editing software to change the bit depth when saving the image, or you can also use online converters.

Cladiuss
  • 1,271
  • 1
  • 14
  • 27
  • This works. This should be the correct answer. I used imagemagick to convert PNGs from 8-bit to 32-bit. – Krt_Malta Apr 21 '23 at 07:48