How to get thumbnail image in magento 2

7.2k views Asked by At

I have use this code in magento 2

$media_url = $storeObj->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$baseimage          = $media_url.'catalog/product' . $_product->getImage();  

Output: http://localhost/smithbuy/pub/media/catalog/product/w/d/wd7500aaks.jpg

But, I want 
http://localhost/smithbuy/pub/media/catalog/product/cache/1/image/700x700/e9c3970ab036de70892d86c6d221abfe/w/d/wd7500aaks.jpg

Please help me.

1

There are 1 answers

0
Abhinav Kumar Singh On

Use the following code to avail the thumbnail image in the Magento:

$Media = $product->getMediaGalleryEntries();
foreach ($Media as $image) {
    $image->getTypes();
}

getTypes() returns an array that may contain the following vlaues:

  • image
  • small_image
  • thumbnail

If it contains thumbnail then it's the thumbnail image.