0

In Related Product Slider, All Images are of different size and default Magento is not resizing them. Screenshot : https://prnt.sc/oax7yl

enter image description here I want to show all images of the same size.

In view.xml, I have added the width and height of Image but not worked.

<image id="related_products_list" type="small_image">
              <width>240</width>
              <height>300</height>
            </image>

Please suggest me some solution.

1

for this, you have to upload the image of the same dimensions for all products you want if you upload the image of different dimension it will create this issue. this issue can be solved by CSS but it is not recommended because some time image might get stretched out so the best solution is to upload the image of the same dimensions for all products

0

Below code solve the issue:-

<?php
$objectManager =\Magento\Framework\App\ObjectManager::getInstance();
$helperImport = $objectManager->get('\Magento\Catalog\Helper\Image');
$imageUrl = $helperImport->init($_product, 'product_page_image_small')
->setImageFile($_product->getFile()) // image,small_image,thumbnail
->resize(300)
->getUrl();
?>

I used this code because the issue not solved after doing changes in view.xml.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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