4

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.

  • Maybe you change size of product pictures? Without regenerating pictures? – BartZalas Aug 4 '18 at 22:58
  • Please check my answer. – Rohan Hapani Aug 5 '18 at 5:38
  • my photo is 733, in product view is 670 but quality is not high @BartZalas – niceonelee Aug 5 '18 at 8:19
  • please check @RohanHapani – niceonelee Aug 5 '18 at 8:19
2

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();
    }
}
| improve this answer | |
  • i already edited 'vendor/magento/module-catalog/Model/Product/Image.php' but i dont understand File : CompanyName/ModuleName/etc/di.xml ? the path is ? @RohanHapani – niceonelee Aug 5 '18 at 8:17
  • What is your magento root path? – Rohan Hapani Aug 5 '18 at 8:21
  • can you please mention folder name...which is into app/code/ ? – Rohan Hapani Aug 5 '18 at 8:22
  • I made a module to make it easier to edit this value in the admin. See github.com/superdav42/magento-image-quality. Just installing it will increase the quality to 85 but you can change it to whatever you want in the admin. Using 100 is actually not a good idea as it will greatly increase your file size and have no noticeable increase in quality from something more reasonable like 92. – David Stone Sep 6 '19 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.