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

  • author-img Nidhi Arora
  • 5 years
  • 596 views

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

    1250 Pittsford Victor Road Ste 310
    Pittsford, NY 14534

    Development Center

    Plot no. 10, Rajiv Gandhi
    Chandigarh Technology Park