Magento has own resize engine that can resize catalog image on your own desire width and height.That means you can resize image with fixed width and variable height or you can set fixed height with variable width.Also you can resize image with no white background in magento means you remove white background from your image background.So to fit or remove white background use keepFrame(false).

please take a quik look of some functions that I have used in below coding like :
1)constrainOnly :

constrainOnly(bool $flag) : it guarantees that image will not be bigger than it was.we can use it before resize() and default value is true.

2)keepAspectRatio :

keepAspectRatio(bool $flag) : it guarantees that image width/height will not be contorted.we can use it before resize() and default value is true.

3)keepFrame :

keepFrame(bool $flag) : it guarantees that image will have dimension and white background can managed if image is not fit with desired dimention.That means set keepFrame(false) remove the background and set image with desired width/height

for fixed with I have width : 500

[crayon-5e452c945041b523418434/]

for fixed with I have height : 500

[crayon-5e452c9450423857456229/]
Also you can specify the height and width image to image would not exceed that you have mentioned.
[crayon-5e452c9450427889271555/]
You can resize image through Varien_Image if you are using code in custom script or any where else.
I am here checked if there is rsized image or not if not I am creating a new resized image propertioanly with heght and width with Varien_Image.
[crayon-5e452c945042b554137214/]

Sometimes you have only image url like http://jyotiranjan.in/customimage/testimage.jpg so you want to resize that.For that lets how I am resizing that image.Now I am creating a resized folder and have to save that resized image in that folder.

[crayon-5e452c945042f654391234/]

Resize image with no white background in magento
The following two tabs change content below.
Jyotiranjan is one of passionate programmer who has been working in magento since 6 years and in the mean time he has developed enormous amount of modules and customisation of sites. He loves to write blogs and travel for long journeying.

Latest posts by Jyotiranjan Biswal (see all)

Tagged on:                             

3 thoughts on “Resize image with no white background in magento

  • June 12, 2015 at 10:49 am
    Permalink

    Thanks Jyotiranjan, for sharing this solution. It’s an easy way to re-size the images with no white background in Magento.

    Check this Background Image Switcher Extension by FME: http://www.fmeextensions.com/magento-background-images.html

    This extension allows you to configure different background images for different events like Christmas, holidays, etc. The images are automatically changed according to the pre-configured store.

    Reply
  • May 4, 2016 at 9:03 pm
    Permalink

    It is very stupid that every one writing the same code everywhere without telling which file to edit. Guys stop copieng it over and over again

    Reply
    • May 5, 2016 at 7:59 pm
      Permalink

      I can see you have got totally frustrated.

      Most of time this code implements in list.phtml if you have custom theme with custom package then that file will be at (app/design/frontend/[custom_package]/[custom_theme]/template/catalog/product/) else that file is at by default in (app/design/frontend/base/default/template/catalog/product/) .

      open list.phtml file and check line no near to 50 for list mode and 95 for grid mode.

      The code and logic is described here in blog is for managing image in magento not any other framework. So you can use anywhere in magento for managing images as you like.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *