HOW TO GET FULL PRODUCT IMAGE PATH, HEIGHT, AND WIDTH IN MAGENTO 2 CATEGORY PAGES?

  • author-img Nidhi Arora
  • 8 years

Generally, we directly acquire the image path in Magento 1 by using this code:
$this->getSkinUrl() function;
However, it seems a little hard to correctly figure out the product image path in Magento 2. There are some changes to call the images path. You can get full product image path in the templates by using the code mentioned below:
echo $block->getImage($_product, $image)->getImageUrl();
It will return a full image path, including the cached image path for Magento 2 products.

However, if you also need to get image height and width, you can use the following code:
echo $block->getImage($_product, $image)->getHeight();
It will return you the image height.
echo $block->getImage($_product, $image)->getWidth();
And, it will help you to return the image width.

We hope this blog post helps you. Let us know how would you go about this and share your own Magento 2 coding tips and tricks.

Download Blog

ENQUIRY

Ready to Get Started

Communication is the key for us to understand each other. Allow us to understand
your requirements or queries. Present us with an opportunity to serve you.

Fill out the form and out team will get back to you
within 24 hours

    Head Office

    815 Brazos St STE 500, Austin,
    TX 78701, USA