How can I get an image URL from the image name?
Please provide me steps and also let me where need to keep code(folder or file location) to get URL.

| improve this question | | | | |

You can't get product image by product name only. You need to load product by SKU or ID and then you can get the image details using the following code.

$prdId = 35;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$prdoduct = $objectManager->get('Magento\Catalog\Model\Product')->load($prdId);
$store = $objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore();

$productImageUrl = $store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $prdoduct->getImage();
$productUrl  = $product->getProductUrl();
| improve this answer | | | | |
  • Magento 1+ I know only (/skin/frontend/default/default/images/color.jpg), now just want to know where in the frontend pages this images displaying. – irshad Aug 19 '19 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.