Howto downsize product images in Magento using Mage_Catalog_Helper_Image

or

“How can I downsize large product images but not enlarge small images?”

simple as:

syntax:

$this->helper('catalog/image')
->init($_product, 'image')
->keepFrame(false)
->constrainOnly(true)
->resize(650);

example:

$this->helper('catalog/image')
->init($_product, 'image')
->keepFrame(false)
->constrainOnly(true)
->resize(650);

explanation:

$this->helper(‘catalog/image’)

loads the ‘Mage_Catalog_Helper_Image’ located at ‘app/code/core/Mage/Catalog/Helper/Image.php’

(NOTE: it only handles instances of ‘Mage_Catalog_Model_Product’)

[why not categories? - they can have images too!!]

Mage_Catalog_Helper_Image::init($_product, ‘image’)

loads the actual product in the helper

Mage_Catalog_Helper_Image::keepFrame(false)

avoids getting the small image in original size on a solid background color presented (can be handy not to break some layouts)

Mage_Catalog_Helper_Image::constrainOnly(false)

avoids getting small images bigger

Mage_Catalog_Helper_Image::resize(600)

sets the desired width to 600px and the height accordingly (proportional by default)

Check ‘app/code/core/Mage/Catalog/Helper/Image.php’ for more handy methods!

Hope this helps someone.

May 13th, 2009 / Tech Talk / tim

One Response to “Howto downsize product images in Magento using Mage_Catalog_Helper_Image”

  1. Roman says:

    This was very helpful, thanks!

Leave a Reply