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
class Mage_Catalog_Model_Product_Image extends Mage_Core_Model_Abstract
{
protected $_width;
protected $_height;
protected $_quality = 90;
/** CODE OMMITED **/
/**
* Set image quality, values in percentage from 0 to 100
*
* @param int $quality
* @return Mage_Catalog_Model_Product_Image
*/
public function setQuality($quality)
{
$this->_quality = $quality;
return $this;
}
/** CODE OMMITED **/
/** This function resizes the image**/
/**
* @return Varien_Image
*/
public function getImageProcessor()
{
if( !$this->_processor ) {
// var_dump($this->_checkMemory());
// if (!$this->_checkMemory()) {
// $this->_baseFile = null;
// }
$this->_processor = new Varien_Image($this->getBaseFile());
}
$this->_processor->keepAspectRatio($this->_keepAspectRatio);
$this->_processor->keepFrame($this->_keepFrame);
$this->_processor->keepTransparency($this->_keepTransparency);
$this->_processor->constrainOnly($this->_constrainOnly);
$this->_processor->backgroundColor($this->_backgroundColor);
$this->_processor->quality($this->_quality);
return $this->_processor;
}
At the beginning of the file the quality level is hardcoded to 90
and then applied in getImageProcessor()
. 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?
Best Answer
In
etc/view.xml
of your current theme, you can update product image sizeMake sure you resize with the expect ratio.
Use additional tag
<frame>
to prevent white borders on image. Use this code as example:Check all other tags, not just a tag with the id
product_page_main_image
check others too.<frame>false</frame>
was an issue in previous versions, it was not working in old 2.x versions and reported earlierNote: If you still getting white border issue, then you need to use the below fix until it's offically released: