Home    Articles


How to get product image in magento


In order to get the product image in magento you need to load the product.
If the product is already loaded, you can try to get the image like that:

echo Mage::getModel('catalog/product_media_config')->getMediaUrl( $_product->getThumbnail() );
//also try getImage(),getSmallImage(), getThumbnail()

If this doesn’t work , get it id of the product and load it:

$_pr = Mage::getModel('catalog/product')->load($_item->getId());
// now get the image
echo Mage::getModel('catalog/product_media_config')->getMediaUrl( $_pr->getThumbnail() );

There are other way to get the product image:

1) Get the product image in mageto with resize:

echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(38, 38);

2) Get the image directly using the product object

$product = Mage::getModel('catalog/product')->load(12); //Product Id
  $imageUrl = $product->getImage();


 $smallImage = $product->getSmallImage();


  $thumbnailImage = $product->getThumbnail();

Few methods may not work, but the getting products image should be simple enough.
That’s all.

…first time posted on w3bdeveloper.com