Magento – Programatically resize and crop images

imagejavascriptPHP

There's a javascript plugin called PictureFill.js:

https://github.com/scottjehl/picturefill

I wondered if anyone has ever used this on a Magento site and whether I could get some tips on how to implement this.

If not, can anyone tell me of an alternative so I'm able to use server side code to size and crop images?

Thanks in advance for any help.

Best Answer

Here's an example how product image is handled in product media.phtml block:

$_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'image')->resize(265).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';

This example resizes image to 256 x 256 resolution (hence only single 256). There're other options as well which determine how the image is cropped, how the aspect ratio is handled, which background color to use and so on.

Related Topic