Magento 2 – Change Featured Product Image Size

magento2product

Hi i want to Create custom Featured Product in Magento 2. Below code use to get Product images:

$productImage = $block->getImage($_product, $image);
if ($pos != null) {
    $position = ' style="left:' . $productImage->getWidth() . 'px;'
        . 'top:' . $productImage->getHeight() . 'px;"';
}

echo $productImage->toHtml();

Currently Getting Image size as per Define in etc/view.xml in Theme, But i want to change Custom Image size for feature product in Homepage.

Best Answer

In your PHTML file you need to set $image = 'homepage_page_grid'; tag as I show here.

then use this $image tag in product Image like below.

$productImage = $block->getImage($_product, $image);

now go to vendor_name/theme/name/etc/view.xml file and add your image with id that you set in PHTML file.

<image id="homepage_page_grid" type="thumbnail">
            <width>200</width>
            <height>200</height>
        </image>

Hope this will help you.

Related Topic