0

I got this method in my RelatedProduct class that gets related product image URL

public function getProductImageUrl($product)
{
    return $this->_storeManager->getStore()
                ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();
}

and when I use it in my template

<img src=" <?= $product->getProductImageUrl($relatedProduct) ?> ">

the image is too large, it takes up whole screen.

How can I set the size of the image to base image size, preferably without having to add css styling for it? Can I do it in some .xml file?

rits
  • 753
  • 2
  • 12
  • 25

1 Answers1

0

Here you have the full answer : https://magento.stackexchange.com/a/122570/33619
You have to use the view.xml file in your theme to set your different sizes and them call them in your template by their code.

In your view.xml

<image id="your_image_id" type="small_image">
    <width>152</width>
    <height>190</height>
</image>

In your template

<?php echo $block->getImage($product, 'your_image_id')->toHtml(); ?>
Matthéo Geoffray
  • 2,684
  • 2
  • 20
  • 45