5
votes

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 :)

1
I was hoping to do it with the builtin functionality. but that does the job. thanks @R.S - Vítor Manfredini

1 Answers

6
votes

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()) ?>" />