Product Images – High-Resolution Square Images on Product List Pages

imageproduct-imagesproduct-list

I'm trying to show square product images on the product list pages, where images for hundreds of products range in dimensions.

When I use this adaptive resize

<img id="product-collection-image-<?php echo $_product->getId();" 
src="<?php echo $this
->helper('catalog/image')
->init($_product, 'small_image')
->constrainOnly(FALSE)
->keepAspectRatio(TRUE)
->keepFrame(FALSE)
->adaptiveResize(300,300); ?>" width="300" height="300"

it shows squares but the image quality is bad. When I set constrainOnly(TRUE), the quality is good, but the squares have some black in them to fill the rest of the square that the image doesn't fill.

How can I get as high as possible image resolution whilst also squaring the images (ideally showing the centre of the image)? Is there any alternative method?

(I tried this adaptive resize too)

Update

I accepted the solution below however I was still left with bad resolution on images. Because I am working with images of different dimensions, some landscape, some portrait, the best solution for me was to manually crop the images into squares (in gimp, change the relative scale so the smallest side is equal to the size of the image I need whilst retaining aspect ratio, then change canvas size). All the solutions I've seen don't work well on images like these.

Best Answer

You can just use resize(width, height) with constrainOnly(TRUE).

Try this:

<img id="product-collection-image-<?php echo $_product->getId();?>" 
src="<?php echo $this
->helper('catalog/image')
->init($_product, 'small_image')
->constrainOnly(TRUE)
->keepAspectRatio(TRUE)
->keepFrame(FALSE)
->resize(300,300); ?>" width="300" height="300"/>

Reference: link.

Hope this helps.

Related Topic