HOW TO GET FULL PRODUCT IMAGE PATH, HEIGHT, AND WIDTH IN MAGENTO 2 CATEGORY PAGES?
Generally, we directly acquire the image path in Magento 1 by using this code:
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.