Magento – How to increase the quality of product photos JPG (Magento 2)

magento2product-images

The JPG compression on Magento 2 is very strong, so that the quality of product images get really bad in Catalog and Product view. How can I change the Image compression for JPG's in Magento 2?

Best Answer

This solution works for me :

File : {Vendor}/{Module}/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="{Vendor}\{Module}\Model\Product\Image" />
</config>

File : {Vendor}/{Module}/Model/Product You can set the quality to whatever you want. Then flush image cache.

namespace {Vendor}\{Module}\Model\Product;

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

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

        parent::_construct();
    }
}
Related Topic