Search code examples
magento2

Get product image from Product Model Magento 2


I am grabbing a product object with:

    $productId = 9184;
    $objectManagerProd = \Magento\Framework \App\ObjectManager::getInstance(); 
    $currentproduct = $objectManagerProd->create('Magento\Catalog\Model\Product')->load($productId);

I have tried to grab the product image with the image helper but it is not working. I have tried getImage() as well. Any body can help? Thanks!


Solution

  • Get product image from Product in PHTML file for Magento 2

    $_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $imageHelper  = $_objectManager->get('\Magento\Catalog\Helper\Image');
    <?php $image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize($imagewidth, $imageheight)->getUrl(); ?>