October 6, 2011

Customize Magento’s Image Resize Functionality

If you want to control the aspect ratio or the white border around your image locate the appropriate file and edit the following properties.

For example in list.phtml

<img src=”<?php echo $this->helper(‘catalog/image’)->init($_product, ‘small_image’)->resize(150,150)->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(TRUE); ?>” width=”150″ height=”150″ alt=”<?php echo $this->stripTags($this->getImageLabel($_product, ‘small_image’), null, true) ?>” />
  • constrainOnly(true) This will not resize an image that is smaller than the dimensions inside the resize() part.
  • keepAspectRatio(true) This will not distort the height/width of the image.
  • keepFrame(false) This will not put a white frame around your image.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>