cancel
Showing results for 
Search instead for 
Did you mean: 

Some product images are the wrong size

Some product images are the wrong size

For every couple of products that one of our customers adds to their site one of them will upload with a single incorrect image. The image source file has the same dimensions as the two products next to it in the photo below, but when uploaded, Magento is adding a white border on that particular one. We are running magento 2.3.2.incorrect-prpoduct-image.jpg

 

2 REPLIES 2

Re: Some product images are the wrong size

Hello @DTF Digital 

 

You can try following code for resize the product images in magento 2.

First of all, you need to call helper file. Magento\Catalog\Helper\Image to resize product image.

 

$_product = $productObject; // Your Product Object

$_imageHelper = $this->helper('Magento\Catalog\Helper\Image');
 
$_productImage = $_imageHelper->init($_product, 'thumbnail', ['type'=>'thumbnail'])
               ->constrainOnly(TRUE)
               ->keepAspectRatio(TRUE)
               ->keepTransparency(TRUE)
               ->resize('256','128')
               ->getUrl();
 
If my answer is useful, please Accept as Solution & give Kudos

Re: Some product images are the wrong size

Thanks for your reply, unfortunately resizing the image isn't the problem, it's just the odd image that's scaled incorrectly, for a so far unknown reason.