I've noticed on our Magento 1.9.3.1 store that when Magento puts product images into cache it's actually making them bigger. I'm not sure where to start debugging this or if there is a fix for it?
To give you an example I uploaded a image which was compressed to 92kb with PhotoShops Save for Web feature. However when I checked the frontend of the website I found that it had increased to 209kb.
The larger version of the file is coming from the Magento cache for product images, it's file path is:
media/catalog/product/cache/9/thumbnail/c96a280f94e22e3ee3823dd0a1a87606/i/m/img_4901-3v2.jpg
The original file still has the 92kb file size and is located in:
media/catalog/product/i/m/img_4901-3v2.jpg
Why & How could Magento be making the file bigger? Also why is it putting the cahed image in a thumbnail
directory, all the cached versions of this image are being put in the thumbnail directory, i.e.
media/catalog/product/cache/9/thumbnail/200x/1ac472b2e3bed24f4b7f75082897d970/i/m/img_4901-3v3.jpg
media/catalog/product/cache/9/thumbnail/535x/1ac472b2e3bed24f4b7f75082897d970/i/m/img_4901-3v3.jpg
Where in the code does Magento process images for the cache?
I've looked in lib/tcpdf/tcpdf.php at $img->setCompressionQuality($this->jpeg_quality);
. I've also checked template/catalog/product/view/media.phtml but couldn't find anything.
Best Answer
I found where Magento is saving the file, it actually re-saving it with a higher compression/image quality than was used in PS, thus the file is getting bigger. I can fix it but it would mean overriding a Magento core file.
This is the file responsible for increasing the image quality: app/code/core/Mage/Catalog/Model/Product/Image.php
At the beginning of the file the quality level is hardcoded to
90
and then applied ingetImageProcessor()
. By commenting out$this->_processor->quality($this->_quality);
temporarily I can see that the issue goes away.Why would Magento do this? This seems like it should be a common issue too. Is the best solution just to create a class override for this core Magento file?