Tuesday, January 22, 2013
How to resize product/custom image in magento
>> Resize product image with product object.
<img src="<?php echo Mage::helper('catalog/image')->init($_product, 'image')->resize(70,155);?>"/>
>> Resize a custom Image.
// Image name
$image = "";
// actual image path
$imageUrl = Mage::getBaseDir('media'). DS .'justonestepsolution'. DS .$image;
// Give resized image path to be saved
// here, the resized image will save in media/justonestepsolution/resized folder
$imageResized = Mage::getBaseDir('media'). DS .'justonestepsolution'. DS .'resized'. DS .$image;
// image will resize only if the image file exists and the resized image file doesn't exist
if (!file_exists($imageResized) && file_exists($imageUrl))
{
$imageObj = new Varien_Image($imageUrl);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(FALSE);
$imageObj->resize(300, null);
$imageObj->save($imageResized);
}
enjoy :-)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment