I checked my site on google page insights and it tells me that i should optimize some images. So i optimized the relevant images in the media/catalog/product directory. As the images get served from the media cache directory I flushed the catalog images cached and the magento cache and then rechecked, Still it's there. Then when i checked the cached image becomes larger in size than the original. Why is it happening? And how can i make the optimized image come to cache image directory?

  • Hi I am seeing the exact same behaviour in Magento, Did you find any solution to this?
    – user40629
    Commented Jun 5, 2016 at 18:18

1 Answer 1


I found a possible solution. We saved all our jpgs with a quality of 80% with photoshop. The Magento Helper inits the product image and the default quality is set to 100%. In my opinion the helper saves the image with quality 100% to the cache, and because of this the filesize is larger than the original.

Loading images like that fixed the issue for us:

Mage::helper('catalog/image')->init($_product, 'image')->setQuality(80);

Furthermore we had to override getGalleryImageUrl function of the Product_View_Media_Block to apply the fix to the gallery images.

class Custom_Images_Block_Catalog_Product_View_Media extends Mage_Catalog_Block_Product_View_Media {
     * Fix for Images -> setQuality(80)
     * @param null|Varien_Object $image
     * @return null|string
    public function getGalleryImageUrl($image)
        if ($image) {
            $helper = $this->helper('catalog/image')
                ->init($this->getProduct(), 'image', $image->getFile())

            $size = Mage::getStoreConfig(Mage_Catalog_Helper_Image::XML_NODE_PRODUCT_BASE_IMAGE_WIDTH);
            if (is_numeric($size)) {
            return (string)$helper;
        return null;


If we open the edited jpg with 80% quality with photoshop again and do a save with 100% we got the same filesize as the image of the magento cache has.

hope this fix is helpful for someone...

  • Thanks for the solution. I'll check on this and mark this correct if this solves the issue. Commented Jan 27, 2017 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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