Magento: Custom function to resize image proportionally

In my previous article to resize image in Magento, I had written direct code to resize any image. Here, I will be writing a simple function to resize image proportionally, which can be kept in the helper file of the module (as helper file can be accessed by any template (.phtml) file).

Here is the custom image resize function. This function will resize image proportionally.

$imagePath is the path where the image is stored/saved. This directory must be inside ‘media’ directory. Like, if we specify ‘xyz/image‘ as $imagePath then our image path must be ‘media/xyz/image/abc.jpg‘ (the $imageName is abc.jpg)

We have defined the width and height to be 400 and 300 respectively. So, a new folder will be created named ‘400×300’. The new resized image will be saved here.

If width is null and height is 300 then the image will be resized proportionally with fixed height of 300px. And the folder name will be ‘x300’.

If width is 400 and height is null then the image will be resized proportionally with fixed width of 400px. And the folder name will be ‘400x’.

If both width and height are null then the image is resized with height ‘100’ and width ‘100’. And the folder name will be ‘100×100’.

What I want to do is have the product images appear without the white boxes that they currently show up in. If I incorporate the script above to resize the images, will it do that?

Thanks,
Jenn

Test

Mardar chod chal hi nih raha hai

Test

Mardar chod chal hi nih raha hai

Test

Mardar chod chal hi nih raha hai

Test

Mardar chod chal hi nih raha hai

Test

Mardar chod chal hi nih raha hai

Test

Mardar chod chal hi nih raha hai

Suman

Nice Post

About

Mukesh Chapagain is a graduate of Kathmandu University (Dhulikhel, Nepal) from where he holds a Masters degree in Computer Engineering. Mukesh is a passionate web developer who has keen interest in open source technologies, programming & blogging. more...