My site always gets an error of image optimization in PageSpeedInsights tool. I want to know if there is any provision of extension for the same or only code will help.

1 Answer 1


Magento uses the catalog image init function to resize your uploaded product images across several pages, here are the code snippet for different pages to show you how magento resize images -:

For category pages, Magento is creating 135 by 135 small product images -:

<?php echo  $this->helper('catalog/image')->init($_product, 'small_image')
            ->resize(135, 135);?>

For product pages, Magento is creating 270 by 270 main product images -:

<?php echo  $this->helper('catalog/image')->init($_product, 'image')
            ->resize(270, 270);?>

For basket/checkout pages, Magento is creating 75 by 75 thumbnail images -:

<?php echo  $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(75, 75);

Those images get saved at the following location /media/catalog/product/cache/ based on the following factors

1) Store - media/catalog/product/cache/1/ - 1 is store ID

2) Image type and size - media/catalog/product/cache/1/small_image/135x135/ - image type could be image, small_image and thumbnail and size could be any numeric value

3) Options chosen for resizing (constrainOnly, keepAspectRatio, keepFrame, keepTransparency, backgroundColor) as explained in the above post by @prince - media/catalog/product/cache/1/small_image/135x135/9df78eab33525d08d6e5fb8d27136e95 - This md5 string is for default resizing 9df78eab33525d08d6e5fb8d27136e95 but based on the options this md5 string could change.

The above is basics around how magento generate those resized or cached images and yes they are not optimised and unfortunately they will require further optimisation which is not possible manually because of the amount images get created on your site based on the above mentioned factors. There are several APIs available to optimise those images like Kraken.io, ImageOptim, Smush.it etc. which you can implement if you have development experience or alternatively you can third party extensions. We use the following plugin on our Magento websites


Hope it helps, thanks

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.