Magento - Resize images, keep aspect ratio, crop what exceeds the size

18,881

Take a look @

Since magento has change there page link structure try http://web.archive.org/web/20140707042130/http://www.magentocommerce.com/boards/viewthread/47269/

Crop product thumbnail images to clean square

Try

<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(120,null); ?>" width="120" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
Share:
18,881
Vítor Manfredini
Author by

Vítor Manfredini

Updated on June 09, 2022

Comments

  • Vítor Manfredini
    Vítor Manfredini almost 2 years

    I want to resize an image in magento keeping its aspect ratio and make it fill a rectangle with another aspect ratio.

    Example:

    My image is 640x480

    And my rectangle is 100x50

    I want the image to fill ALL the rectangle and crop what exceeds it.

    I'm aware of keepFrame(FALSE) - It doesn't make the image fill the rectangle, instead it makes it fit inside and doesnt crop anything.

    Also, if you familiar with Wordpress, what I want is the as doing: *add_image_size('home',370,256,true);*

    Thank you :)