1. Add the following function in your Helper file
public function resizeImage($imageName, $width=NULL, $height=NULL, $imagePath=NULL) { $imagePath = str_replace("/", DS, $imagePath); $imagePathFull = Mage::getBaseDir('media') . DS . $imagePath . DS . $imageName; if($width == NULL && $height == NULL) { $width = 450; $height = 450; } $resizePath = $width . 'x' . $height; $resizePathFull = Mage::getBaseDir('media') . DS . $imagePath . DS . $resizePath . DS . $imageName; if (file_exists($imagePathFull) && !file_exists($resizePathFull)) { $imageObj = new Varien_Image($imagePathFull); $imageObj->constrainOnly(TRUE); $imageObj->keepAspectRatio(TRUE); $imageObj->resize($width,$height); $imageObj->save($resizePathFull); } $imagePath=str_replace(DS, "/", $imagePath); return Mage::getBaseUrl("media") . $imagePath . "" . $resizePath . "/" . $imageName; }
2. In your template file call image src :
Mage::helper('yourmodule')->resizeImage('imagename', 545, 160, 'imagepath')
0 Comments