Magento – Magento 2.2.5 – How to increase the quality of product view photos JPG

image qualitymagento-2.2.5magento2product-images

I'm using Magento 2.2.5
How to increase the quality of product view photos JPG
Because in product view the JPG quality is not high, but link out to see the photo is high quality.
How to fix it?
Please help.

Best Answer

The quality of image is set in Magento\Catalog\Model\Product\Image at line no 39 protected $_quality = 80;

You can override this in you module.

File : CompanyName/ModuleName/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\Catalog\Model\Product\Image" type="CompanyName\ModuleName\Model\Product\Image" />
</config>

File : CompanyName/ModuleName/Model/Product You can set the quality to which you want to set. Then flush image cache.

namespace CompanyName\ModuleName\Model\Product;

class Image extends \Magento\Catalog\Model\Product\Image {

    protected function _construct() {
        $this->_quality = 100;

        parent::_construct();
    }
}
Related Topic