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

3 Responses to “Howto downsize product images in Magento using Mage_Catalog_Helper_Image”

  1. Roman says:

    This was very helpful, thanks!

  2. Frederik says:

    Great description, thanks!

    Is it somehow possible to get the url of the original, unmanipulated, image as well? I would like to access some 300-dpi files but can’t find any methods in the documentation. The files appear to be available in the media folder.

  3. Frederik says:

    I found the solution myself in the meantime. It was as simple as $_image->url in the getGalleryImages() loop in media.phtml.

Leave a Reply