The JPG compression on Magento 2.1 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.1 ?


1 Answer 1


I found this How to increase the quality of product photos JPG (Magento 2),

inside - vendor/magento/module-catalog/Helper/Image.php

You will find the generic:

public function setQuality($quality)
    return $this;  

If you grep for its usage you will find a method of the same name in:


and inside that file:

 * Default quality value (for JPEG images only).
 * @var int
protected $_quality = 80;
It is this value - that needs setting to 95.

it works, but it's modification of the core file.

What we need is the code bellow from M1 for M2.

echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->resize(42, 50)->setQuality(95);

problem is where to add this in

  • 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. Sep 6, 2019 at 19:40

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