If you go this page, you’ll notice I’m displaying the same version of image at 2 different places: one for the cloud zoom, and one at the middle of the page without zooming.
I’m currently using 2 different lines of code to generate the image and then return the URL of it, which essentially does the same thing:
<?php /* for cloud zoom */ echo $this->helper('catalog/image')->init($_product, 'image')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->setWatermarkImageOpacity(0)->resize(600, null);?>
<?php /* for middle page */ echo $this->helper('catalog/image')->init($_product, 'image')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->setWatermarkImageOpacity(0)->resize(600, null);?>
This is undoubtedly a lame solution because: 1) it occupies more disk storage as there are 2 distinct image files which are essentially the same image; 2) it significantly slows the page load as the user has to download both images.
So my question is how can I use the same version of image at multiple places in Magento? Is there any way to get the resize() method to return the URL of the image?
Thanks!
Mage_Catalog_Helper_Imagehas a__toString()method that does exactly that:HTH