How to get product image path by product id in magento 2how can I get an image to be used in mobile app by rest apiProduct cdn image path issuemagento get product url for csv fileMagento 2: How to get resize image for Custom Module?Display Customized image in place of Base image under “Recently added items”Magento2 product image path issueMagento 2 get cached url full path of custom attributeMagento 2.2.4 : Image full path not gettingMagento 2: How to remove input option from grid filterHow to get product image by product Id in magento2Product page is not displayed: Magento 2

Does the average primeness of natural numbers tend to zero?

Could a US political party gain complete control over the government by removing checks & balances?

If a centaur druid Wild Shapes into a Giant Elk, do their Charge features stack?

Pristine Bit Checking

Calculate Levenshtein distance between two strings in Python

"listening to me about as much as you're listening to this pole here"

What are the advantages and disadvantages of running one shots compared to campaigns?

Landing in very high winds

What to wear for invited talk in Canada

Why do we use polarized capacitors?

Unbreakable Formation vs. Cry of the Carnarium

I see my dog run

How can I plot a Farey diagram?

Is there any use for defining additional entity types in a SOQL FROM clause?

Shall I use personal or official e-mail account when registering to external websites for work purpose?

What causes the sudden spool-up sound from an F-16 when enabling afterburner?

A poker game description that does not feel gimmicky

Doomsday-clock for my fantasy planet

Typesetting a double Over Dot on top of a symbol

Should the British be getting ready for a no-deal Brexit?

Where to refill my bottle in India?

Was there ever an axiom rendered a theorem?

Information to fellow intern about hiring?

Why was the "bread communication" in the arena of Catching Fire left out in the movie?



How to get product image path by product id in magento 2


how can I get an image to be used in mobile app by rest apiProduct cdn image path issuemagento get product url for csv fileMagento 2: How to get resize image for Custom Module?Display Customized image in place of Base image under “Recently added items”Magento2 product image path issueMagento 2 get cached url full path of custom attributeMagento 2.2.4 : Image full path not gettingMagento 2: How to remove input option from grid filterHow to get product image by product Id in magento2Product page is not displayed: Magento 2






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















Hello friends i want to fetch image path like var/www/magento/pub/media
i wand to display image in admin grid i am using rendarar to get image
image path by passing Product id. How this can be achieved ? please explain



thanks
Adarsh Shukla










share|improve this question
























  • please refer to this link magento.stackexchange.com/questions/249393/…

    – Ramkishan Suthar
    Nov 20 '18 at 11:53











  • hello sir thanks for reply but but i was looking for path not url

    – Adarsh Shukla
    Nov 20 '18 at 11:59











  • plaease tell me how to do so

    – Adarsh Shukla
    Nov 20 '18 at 11:59











  • ok you mean absolute path?

    – Ramkishan Suthar
    Nov 20 '18 at 12:00











  • yes sir like var/www/magento/pub/media

    – Adarsh Shukla
    Nov 20 '18 at 12:00

















3















Hello friends i want to fetch image path like var/www/magento/pub/media
i wand to display image in admin grid i am using rendarar to get image
image path by passing Product id. How this can be achieved ? please explain



thanks
Adarsh Shukla










share|improve this question
























  • please refer to this link magento.stackexchange.com/questions/249393/…

    – Ramkishan Suthar
    Nov 20 '18 at 11:53











  • hello sir thanks for reply but but i was looking for path not url

    – Adarsh Shukla
    Nov 20 '18 at 11:59











  • plaease tell me how to do so

    – Adarsh Shukla
    Nov 20 '18 at 11:59











  • ok you mean absolute path?

    – Ramkishan Suthar
    Nov 20 '18 at 12:00











  • yes sir like var/www/magento/pub/media

    – Adarsh Shukla
    Nov 20 '18 at 12:00













3












3








3








Hello friends i want to fetch image path like var/www/magento/pub/media
i wand to display image in admin grid i am using rendarar to get image
image path by passing Product id. How this can be achieved ? please explain



thanks
Adarsh Shukla










share|improve this question
















Hello friends i want to fetch image path like var/www/magento/pub/media
i wand to display image in admin grid i am using rendarar to get image
image path by passing Product id. How this can be achieved ? please explain



thanks
Adarsh Shukla







magento2 image






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 5 at 10:27









Himanshu

1,054722




1,054722










asked Nov 20 '18 at 11:48









Adarsh ShuklaAdarsh Shukla

17513




17513












  • please refer to this link magento.stackexchange.com/questions/249393/…

    – Ramkishan Suthar
    Nov 20 '18 at 11:53











  • hello sir thanks for reply but but i was looking for path not url

    – Adarsh Shukla
    Nov 20 '18 at 11:59











  • plaease tell me how to do so

    – Adarsh Shukla
    Nov 20 '18 at 11:59











  • ok you mean absolute path?

    – Ramkishan Suthar
    Nov 20 '18 at 12:00











  • yes sir like var/www/magento/pub/media

    – Adarsh Shukla
    Nov 20 '18 at 12:00

















  • please refer to this link magento.stackexchange.com/questions/249393/…

    – Ramkishan Suthar
    Nov 20 '18 at 11:53











  • hello sir thanks for reply but but i was looking for path not url

    – Adarsh Shukla
    Nov 20 '18 at 11:59











  • plaease tell me how to do so

    – Adarsh Shukla
    Nov 20 '18 at 11:59











  • ok you mean absolute path?

    – Ramkishan Suthar
    Nov 20 '18 at 12:00











  • yes sir like var/www/magento/pub/media

    – Adarsh Shukla
    Nov 20 '18 at 12:00
















please refer to this link magento.stackexchange.com/questions/249393/…

– Ramkishan Suthar
Nov 20 '18 at 11:53





please refer to this link magento.stackexchange.com/questions/249393/…

– Ramkishan Suthar
Nov 20 '18 at 11:53













hello sir thanks for reply but but i was looking for path not url

– Adarsh Shukla
Nov 20 '18 at 11:59





hello sir thanks for reply but but i was looking for path not url

– Adarsh Shukla
Nov 20 '18 at 11:59













plaease tell me how to do so

– Adarsh Shukla
Nov 20 '18 at 11:59





plaease tell me how to do so

– Adarsh Shukla
Nov 20 '18 at 11:59













ok you mean absolute path?

– Ramkishan Suthar
Nov 20 '18 at 12:00





ok you mean absolute path?

– Ramkishan Suthar
Nov 20 '18 at 12:00













yes sir like var/www/magento/pub/media

– Adarsh Shukla
Nov 20 '18 at 12:00





yes sir like var/www/magento/pub/media

– Adarsh Shukla
Nov 20 '18 at 12:00










3 Answers
3






active

oldest

votes


















2














To get media absolute path you can try below code.



public function __construct(
MagentoFrameworkFilesystemDirectoryList $directoryList

)
$this->directory = $directoryList;

public function getMediaAbsoluteUrl()
$mediaAbsoluteUrl = $this->directory->getPath('media');



I hope it'll work for you.






share|improve this answer

























  • Will This give me product image path by product id ?

    – Adarsh Shukla
    Nov 20 '18 at 12:23












  • it will written absolute path of media directory as per you mentioned in comments.

    – Ramkishan Suthar
    Nov 20 '18 at 12:25











  • is my aim is to get products image by passing product id i am trying to display that image to admin grid

    – Adarsh Shukla
    Nov 20 '18 at 12:27











  • I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.

    – Ramkishan Suthar
    Nov 20 '18 at 12:39











  • You just need to append $product->getImage() after $mediaUrl

    – Ramkishan Suthar
    Nov 20 '18 at 12:40


















3














Add this below code in your file :



protected $_imageHelper;
protected $_productRepositoryFactory;
public function __construct(
.........................
MagentoCatalogHelperImage $imageHelper,
MagentoCatalogApiProductRepositoryInterfaceFactory $productRepositoryFactory,
.........................
)

.........................
$this->_imageHelper = $imageHelper;
$this->_productRepositoryFactory = $productRepositoryFactory;
.........................


public function yourFunction()

$productID = 1;
$product = $this->_productRepositoryFactory->create()->getById($productID);
echo $this->_imageHelper->init($product,'image')->setImageFile($product->getImage())->getUrl();






share|improve this answer























  • sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

    – Adarsh Shukla
    Nov 20 '18 at 12:14












  • i wand to display image in admin grid i am using rendarar to get image

    – Adarsh Shukla
    Nov 20 '18 at 12:21


















1














You can get product image path from below code



 $product_id=20; //enter product id here

$objectManager = MagentoFrameworkAppObjectManager::getInstance();

$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);

$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();

$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();

$mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);


i Hope it help






share|improve this answer




















  • 1





    sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

    – Adarsh Shukla
    Nov 20 '18 at 12:15











  • @AdarshShukla you mean media path?

    – Balwant Singh
    Nov 20 '18 at 12:20











  • yes i wand to display image in admin grid i am using rendarar to get image

    – Adarsh Shukla
    Nov 20 '18 at 12:22











  • okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);

    – Balwant Singh
    Nov 20 '18 at 12:25











  • @AdarshShukla check my updated code . $mediaUrl gives the path what you want

    – Balwant Singh
    Nov 20 '18 at 12:28











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f250642%2fhow-to-get-product-image-path-by-product-id-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














To get media absolute path you can try below code.



public function __construct(
MagentoFrameworkFilesystemDirectoryList $directoryList

)
$this->directory = $directoryList;

public function getMediaAbsoluteUrl()
$mediaAbsoluteUrl = $this->directory->getPath('media');



I hope it'll work for you.






share|improve this answer

























  • Will This give me product image path by product id ?

    – Adarsh Shukla
    Nov 20 '18 at 12:23












  • it will written absolute path of media directory as per you mentioned in comments.

    – Ramkishan Suthar
    Nov 20 '18 at 12:25











  • is my aim is to get products image by passing product id i am trying to display that image to admin grid

    – Adarsh Shukla
    Nov 20 '18 at 12:27











  • I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.

    – Ramkishan Suthar
    Nov 20 '18 at 12:39











  • You just need to append $product->getImage() after $mediaUrl

    – Ramkishan Suthar
    Nov 20 '18 at 12:40















2














To get media absolute path you can try below code.



public function __construct(
MagentoFrameworkFilesystemDirectoryList $directoryList

)
$this->directory = $directoryList;

public function getMediaAbsoluteUrl()
$mediaAbsoluteUrl = $this->directory->getPath('media');



I hope it'll work for you.






share|improve this answer

























  • Will This give me product image path by product id ?

    – Adarsh Shukla
    Nov 20 '18 at 12:23












  • it will written absolute path of media directory as per you mentioned in comments.

    – Ramkishan Suthar
    Nov 20 '18 at 12:25











  • is my aim is to get products image by passing product id i am trying to display that image to admin grid

    – Adarsh Shukla
    Nov 20 '18 at 12:27











  • I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.

    – Ramkishan Suthar
    Nov 20 '18 at 12:39











  • You just need to append $product->getImage() after $mediaUrl

    – Ramkishan Suthar
    Nov 20 '18 at 12:40













2












2








2







To get media absolute path you can try below code.



public function __construct(
MagentoFrameworkFilesystemDirectoryList $directoryList

)
$this->directory = $directoryList;

public function getMediaAbsoluteUrl()
$mediaAbsoluteUrl = $this->directory->getPath('media');



I hope it'll work for you.






share|improve this answer















To get media absolute path you can try below code.



public function __construct(
MagentoFrameworkFilesystemDirectoryList $directoryList

)
$this->directory = $directoryList;

public function getMediaAbsoluteUrl()
$mediaAbsoluteUrl = $this->directory->getPath('media');



I hope it'll work for you.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 12:18

























answered Nov 20 '18 at 12:03









Ramkishan SutharRamkishan Suthar

2,29221435




2,29221435












  • Will This give me product image path by product id ?

    – Adarsh Shukla
    Nov 20 '18 at 12:23












  • it will written absolute path of media directory as per you mentioned in comments.

    – Ramkishan Suthar
    Nov 20 '18 at 12:25











  • is my aim is to get products image by passing product id i am trying to display that image to admin grid

    – Adarsh Shukla
    Nov 20 '18 at 12:27











  • I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.

    – Ramkishan Suthar
    Nov 20 '18 at 12:39











  • You just need to append $product->getImage() after $mediaUrl

    – Ramkishan Suthar
    Nov 20 '18 at 12:40

















  • Will This give me product image path by product id ?

    – Adarsh Shukla
    Nov 20 '18 at 12:23












  • it will written absolute path of media directory as per you mentioned in comments.

    – Ramkishan Suthar
    Nov 20 '18 at 12:25











  • is my aim is to get products image by passing product id i am trying to display that image to admin grid

    – Adarsh Shukla
    Nov 20 '18 at 12:27











  • I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.

    – Ramkishan Suthar
    Nov 20 '18 at 12:39











  • You just need to append $product->getImage() after $mediaUrl

    – Ramkishan Suthar
    Nov 20 '18 at 12:40
















Will This give me product image path by product id ?

– Adarsh Shukla
Nov 20 '18 at 12:23






Will This give me product image path by product id ?

– Adarsh Shukla
Nov 20 '18 at 12:23














it will written absolute path of media directory as per you mentioned in comments.

– Ramkishan Suthar
Nov 20 '18 at 12:25





it will written absolute path of media directory as per you mentioned in comments.

– Ramkishan Suthar
Nov 20 '18 at 12:25













is my aim is to get products image by passing product id i am trying to display that image to admin grid

– Adarsh Shukla
Nov 20 '18 at 12:27





is my aim is to get products image by passing product id i am trying to display that image to admin grid

– Adarsh Shukla
Nov 20 '18 at 12:27













I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.

– Ramkishan Suthar
Nov 20 '18 at 12:39





I am not able to get you, like why you need absolute url for this. If you just need to display product image then link which I have share in starting will work for you.

– Ramkishan Suthar
Nov 20 '18 at 12:39













You just need to append $product->getImage() after $mediaUrl

– Ramkishan Suthar
Nov 20 '18 at 12:40





You just need to append $product->getImage() after $mediaUrl

– Ramkishan Suthar
Nov 20 '18 at 12:40













3














Add this below code in your file :



protected $_imageHelper;
protected $_productRepositoryFactory;
public function __construct(
.........................
MagentoCatalogHelperImage $imageHelper,
MagentoCatalogApiProductRepositoryInterfaceFactory $productRepositoryFactory,
.........................
)

.........................
$this->_imageHelper = $imageHelper;
$this->_productRepositoryFactory = $productRepositoryFactory;
.........................


public function yourFunction()

$productID = 1;
$product = $this->_productRepositoryFactory->create()->getById($productID);
echo $this->_imageHelper->init($product,'image')->setImageFile($product->getImage())->getUrl();






share|improve this answer























  • sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

    – Adarsh Shukla
    Nov 20 '18 at 12:14












  • i wand to display image in admin grid i am using rendarar to get image

    – Adarsh Shukla
    Nov 20 '18 at 12:21















3














Add this below code in your file :



protected $_imageHelper;
protected $_productRepositoryFactory;
public function __construct(
.........................
MagentoCatalogHelperImage $imageHelper,
MagentoCatalogApiProductRepositoryInterfaceFactory $productRepositoryFactory,
.........................
)

.........................
$this->_imageHelper = $imageHelper;
$this->_productRepositoryFactory = $productRepositoryFactory;
.........................


public function yourFunction()

$productID = 1;
$product = $this->_productRepositoryFactory->create()->getById($productID);
echo $this->_imageHelper->init($product,'image')->setImageFile($product->getImage())->getUrl();






share|improve this answer























  • sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

    – Adarsh Shukla
    Nov 20 '18 at 12:14












  • i wand to display image in admin grid i am using rendarar to get image

    – Adarsh Shukla
    Nov 20 '18 at 12:21













3












3








3







Add this below code in your file :



protected $_imageHelper;
protected $_productRepositoryFactory;
public function __construct(
.........................
MagentoCatalogHelperImage $imageHelper,
MagentoCatalogApiProductRepositoryInterfaceFactory $productRepositoryFactory,
.........................
)

.........................
$this->_imageHelper = $imageHelper;
$this->_productRepositoryFactory = $productRepositoryFactory;
.........................


public function yourFunction()

$productID = 1;
$product = $this->_productRepositoryFactory->create()->getById($productID);
echo $this->_imageHelper->init($product,'image')->setImageFile($product->getImage())->getUrl();






share|improve this answer













Add this below code in your file :



protected $_imageHelper;
protected $_productRepositoryFactory;
public function __construct(
.........................
MagentoCatalogHelperImage $imageHelper,
MagentoCatalogApiProductRepositoryInterfaceFactory $productRepositoryFactory,
.........................
)

.........................
$this->_imageHelper = $imageHelper;
$this->_productRepositoryFactory = $productRepositoryFactory;
.........................


public function yourFunction()

$productID = 1;
$product = $this->_productRepositoryFactory->create()->getById($productID);
echo $this->_imageHelper->init($product,'image')->setImageFile($product->getImage())->getUrl();







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 12:01









Rohan HapaniRohan Hapani

6,87931865




6,87931865












  • sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

    – Adarsh Shukla
    Nov 20 '18 at 12:14












  • i wand to display image in admin grid i am using rendarar to get image

    – Adarsh Shukla
    Nov 20 '18 at 12:21

















  • sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

    – Adarsh Shukla
    Nov 20 '18 at 12:14












  • i wand to display image in admin grid i am using rendarar to get image

    – Adarsh Shukla
    Nov 20 '18 at 12:21
















sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

– Adarsh Shukla
Nov 20 '18 at 12:14






sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

– Adarsh Shukla
Nov 20 '18 at 12:14














i wand to display image in admin grid i am using rendarar to get image

– Adarsh Shukla
Nov 20 '18 at 12:21





i wand to display image in admin grid i am using rendarar to get image

– Adarsh Shukla
Nov 20 '18 at 12:21











1














You can get product image path from below code



 $product_id=20; //enter product id here

$objectManager = MagentoFrameworkAppObjectManager::getInstance();

$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);

$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();

$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();

$mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);


i Hope it help






share|improve this answer




















  • 1





    sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

    – Adarsh Shukla
    Nov 20 '18 at 12:15











  • @AdarshShukla you mean media path?

    – Balwant Singh
    Nov 20 '18 at 12:20











  • yes i wand to display image in admin grid i am using rendarar to get image

    – Adarsh Shukla
    Nov 20 '18 at 12:22











  • okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);

    – Balwant Singh
    Nov 20 '18 at 12:25











  • @AdarshShukla check my updated code . $mediaUrl gives the path what you want

    – Balwant Singh
    Nov 20 '18 at 12:28















1














You can get product image path from below code



 $product_id=20; //enter product id here

$objectManager = MagentoFrameworkAppObjectManager::getInstance();

$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);

$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();

$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();

$mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);


i Hope it help






share|improve this answer




















  • 1





    sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

    – Adarsh Shukla
    Nov 20 '18 at 12:15











  • @AdarshShukla you mean media path?

    – Balwant Singh
    Nov 20 '18 at 12:20











  • yes i wand to display image in admin grid i am using rendarar to get image

    – Adarsh Shukla
    Nov 20 '18 at 12:22











  • okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);

    – Balwant Singh
    Nov 20 '18 at 12:25











  • @AdarshShukla check my updated code . $mediaUrl gives the path what you want

    – Balwant Singh
    Nov 20 '18 at 12:28













1












1








1







You can get product image path from below code



 $product_id=20; //enter product id here

$objectManager = MagentoFrameworkAppObjectManager::getInstance();

$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);

$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();

$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();

$mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);


i Hope it help






share|improve this answer















You can get product image path from below code



 $product_id=20; //enter product id here

$objectManager = MagentoFrameworkAppObjectManager::getInstance();

$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);

$store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore();

$imageUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();

$mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);


i Hope it help







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 12:26

























answered Nov 20 '18 at 12:03









Balwant SinghBalwant Singh

3791316




3791316







  • 1





    sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

    – Adarsh Shukla
    Nov 20 '18 at 12:15











  • @AdarshShukla you mean media path?

    – Balwant Singh
    Nov 20 '18 at 12:20











  • yes i wand to display image in admin grid i am using rendarar to get image

    – Adarsh Shukla
    Nov 20 '18 at 12:22











  • okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);

    – Balwant Singh
    Nov 20 '18 at 12:25











  • @AdarshShukla check my updated code . $mediaUrl gives the path what you want

    – Balwant Singh
    Nov 20 '18 at 12:28












  • 1





    sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

    – Adarsh Shukla
    Nov 20 '18 at 12:15











  • @AdarshShukla you mean media path?

    – Balwant Singh
    Nov 20 '18 at 12:20











  • yes i wand to display image in admin grid i am using rendarar to get image

    – Adarsh Shukla
    Nov 20 '18 at 12:22











  • okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);

    – Balwant Singh
    Nov 20 '18 at 12:25











  • @AdarshShukla check my updated code . $mediaUrl gives the path what you want

    – Balwant Singh
    Nov 20 '18 at 12:28







1




1





sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

– Adarsh Shukla
Nov 20 '18 at 12:15





sir, Thanks for reply but this gives url i want path like var/www/magento/pub/media/catalog

– Adarsh Shukla
Nov 20 '18 at 12:15













@AdarshShukla you mean media path?

– Balwant Singh
Nov 20 '18 at 12:20





@AdarshShukla you mean media path?

– Balwant Singh
Nov 20 '18 at 12:20













yes i wand to display image in admin grid i am using rendarar to get image

– Adarsh Shukla
Nov 20 '18 at 12:22





yes i wand to display image in admin grid i am using rendarar to get image

– Adarsh Shukla
Nov 20 '18 at 12:22













okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);

– Balwant Singh
Nov 20 '18 at 12:25





okay then use below code for media url $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $store = $objectManager->get('MagentoStoreModelStoreManagerInterface')->getStore(); $mediaUrl = $store->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);

– Balwant Singh
Nov 20 '18 at 12:25













@AdarshShukla check my updated code . $mediaUrl gives the path what you want

– Balwant Singh
Nov 20 '18 at 12:28





@AdarshShukla check my updated code . $mediaUrl gives the path what you want

– Balwant Singh
Nov 20 '18 at 12:28

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f250642%2fhow-to-get-product-image-path-by-product-id-in-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Sum ergo cogito? 1 nng

三茅街道4182Guuntc Dn precexpngmageondP