5

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

<?php

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

?>

Thanks in advance

1 Answer 1

2

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();
1
  • If it works, You can correct the answer as well as up-vote so it will help others. Thanks. Mar 24, 2017 at 11:11

Your Answer

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

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