{"id":763,"date":"2020-01-15T10:02:22","date_gmt":"2020-01-15T10:02:22","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/01\/15\/get-product-image-url-magento-2\/"},"modified":"2025-03-26T10:15:04","modified_gmt":"2025-03-26T10:15:04","slug":"get-product-image-url-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-product-image-url-magento-2\/","title":{"rendered":"How to Get Product Image URL in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">You may require to <a href=\"https:\/\/meetanshi.com\/blog\/import-product-images-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">import product images in Magento 2<\/a> while migrating the website data or require to get the product image URL to fetch product images, implement custom functionality or developing some features. Today, I&#8217;ve come up with the solution to get product image URL in<em><strong> <\/strong><\/em>Magento 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to get product image URL in Magento 2:<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Vendor\\Extension\\Block;\nuse Magento\\Framework\\View\\Element\\Template;\nuse Magento\\Catalog\\Helper\\Image;\nuse Magento\\Catalog\\Model\\ProductFactory;\nuse Magento\\Framework\\View\\Element\\Template\\Context;\nclass Extension extends Template\n{\n    protected $imageHelper;\n    protected $productFactory;\n    public function __construct(Image $imageHelper, ProductFactory $productFactory, Context,) \n    {\n        $this->imageHelper = $imageHelper;\n        $this->productFactory = $productFactory;\n    }\n    public function getProductImageUrl($id)\n    {\n        try \n        {\n            $product = $this->productFactory->create()->load($id);\n        } \n        catch (NoSuchEntityException $e) \n        {\n            return 'Data not found';\n        }\n        $url = $this->imageHelper->init($product, 'product_thumbnail_image')->getUrl();\n        return $url;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s all about getting Magento 2 product image URL. Let me know if you have any query regarding it by commenting down below! If the tutorial has helped you enough, don&#8217;t forget to rate and share it with other Magento community members.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You may require to import product images in Magento 2 while migrating the website data or require to get the product image URL to fetch&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-763","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/763","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=763"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/763\/revisions"}],"predecessor-version":[{"id":11103,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/763\/revisions\/11103"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}