Using the Image Helper
Just a quick one today about using the image helper in magento.
With just one little snippit of code:
$_imagehelper = Mage::helper('catalog/image');
You can bring back your product images with ease!
There’s been many times in the past when we have used code etc to load product collections outside of the catalog – for instance – the best seller static blocks or dynamic sitemaps. In these instances it is important to use the image helper to return your product image within the system – utilizing the cache and resize options. It is this product object that we need in order to feed it into the helper and bring back our correct image.
If you only have a product ID or SKU to work with then you will need to load the product with either of the following methods before continuing.
$productid = Mage::getModel('catalog/product')->getIdBySku($sku); // if only got SKU
$product = Mage::getModel('catalog/product')->load($productid);
Now we have our product object we can load it into our image helper like so:
<img src="<?php echo $_imagehelper->init($product, 'image')->resize(100) ?>" alt="My product image" />
This should bring our product image back! As you can see its helper->load our product->get our image->resize our image -> echo the result.
I hope this has been of some assistance and thank you for visiting our Magento Blog – Here at Ecommerce Web Design!

Thanks, works great
By the way, any idea on how we can know if the returned image is a placeholder (i.e. product image doesn’t exists)?
Thanks for this small article
Here’s one line code if we already have product ID
Mage::helper('catalog/image')->init(Mage::getModel('catalog/product')->load($id), 'small_image')->resize(32);