In this article, We are going to discuss about How to resize the images in Magento using "Varien_Image" Class. Magento also having the in-built library to resize the image in height and width. You can resize the product images using catalog helper. If you want to upload and resize the images which are not uploaded for product, then this article will help you to how to resize images, such as needing to resize a custom image and display it on the site in special sized areas.
Here I have mentioned the code to resize the images using "Varien_Image" class. This code resizes the images from a specific directory/folder and save the resized image to some other directory/folder.
$_imageUrl = Mage::getBaseDir(‘media’).DS.$image;
$imageResized = Mage::getBaseDir(‘media’).DS.“resized”.$image;
if (!file_exists($imageResized)&&file_exists($_imageUrl)) :
$imageObj = new Varien_Image($_imageUrl);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(FALSE);
$imageObj->resize(140, 140);
$imageObj->save($imageResized);
endif;
Hope this article will work for you.
Here I have mentioned the code to resize the images using "Varien_Image" class. This code resizes the images from a specific directory/folder and save the resized image to some other directory/folder.
$_imageUrl = Mage::getBaseDir(‘media’).DS.$image;
$imageResized = Mage::getBaseDir(‘media’).DS.“resized”.$image;
if (!file_exists($imageResized)&&file_exists($_imageUrl)) :
$imageObj = new Varien_Image($_imageUrl);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(FALSE);
$imageObj->resize(140, 140);
$imageObj->save($imageResized);
endif;
Hope this article will work for you.
Comments · 7
Resize Image
Magento Developers
Expert Magento Developers from India
12 Magento Certified Developers, 100+ Magento Projects Completed
-Thanks
Kathy
Easy Ajax Cart
Php photo gallery
Post a Comment