Magento - Resize images using Varien_Image class

PHP CMS Frameworks November 07, 2012 7 comments
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.

Comments · 7

?
Maniks Read
26 March 2013 at 00:28
Hi this nice post. Thanks for provide the helpful informationabout Magento - Resize images.

Resize Image
?
Unknown
17 April 2013 at 06:48
Hi nice post ,i will try this one .



Magento Developers
?
krishinc
21 July 2013 at 23:19
This is a very informative article . In The Magento product, image is very important if you are forgotten to install product image, then this article will help you to re-size and upload new image by this process.

Expert Magento Developers from India
12 Magento Certified Developers, 100+ Magento Projects Completed
?
Unknown
25 July 2013 at 23:38
Thank you so much. such information will be useful for newbies like me.

-Thanks
Kathy
Easy Ajax Cart
?
Anonymous
2 August 2013 at 00:28
The software is quickly and easily installed on your own web site and with free installation available, there's no hassle to getting started.
Php photo gallery
?
Aguileraq
6 September 2013 at 14:08
This comment has been removed by the author.
?
Vivek sharma
11 September 2013 at 05:23
I want to use watermark functinality of Varien_Image but its not working on my custom module everything else workin fine please suggect how to do this

Post a Comment