Home    Articles


Resize product image in magento


In order to customize image dimensions in magento you need to know that magento does have a method for this.

It's called resize() and can be called from the product object.

Let's assume that that you have the product id.

First step is to load the product as object.

The 2'nd step is to get it's image and to resize it in the same time (same code line). Magento will resize this image once (first time only) and then the image will be saved and used whenever is needed.

Here is the code that does these two steps:

//create the product object by product id
$product_id = 12;
$_product = Mage::getModel('catalog/product')->load( $product_id );
// get the image and resize it
echo $this->helper('catalog/image')->init($_product, 'image')->resize(38, 38);

'image' parameter is used to load the full size image and then to resize it at width 38px and height 38px .

Instead of 'image' you can use also 'small_image' and 'thumbnail'.

I hope it helped.