How to resize product image to a perfect rectangle without white spaces at right and left.

At present we are using 1200*1200 size image, and resizing to 450*300

in result we are getting 450*300 image but white space exits

please help us to fix this issue in magento2

We are using this code presently


$_imagehelper->init($_product, $image)->resize(450, 300);


Thanks in advance

1 Answer 1


set ObjectManager in constructor \Magento\Framework\App\ObjectManager $objectManager;

$imageHelper  = $this->_objectManager->get('\Magento\Catalog\Helper\Image');

$image_url = $imageHelper->init($_product, 'product_page_image_small')->setImageFile($_product->getFile())->resize(450, 300)->getUrl();
  • If it works, You can correct the answer as well as up-vote so it will help others. Thanks. Commented Mar 24, 2017 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.