How to get attribute image in Magento2 using product object?

2 Answers 2


Just inject this \Magento\Catalog\Api\ProductRepositoryInterfaceFactory in your constructor.

protected $_productRepositoryFactory;

public function __construct(
        \Magento\Catalog\Api\ProductRepositoryInterfaceFactory $productRepositoryFactory
) {

    $this->_productRepositoryFactory = $productRepositoryFactory;

Get the image this way:

$product = $this->_productRepositoryFactory->create()->getById($item->getProductId());

reference Get product image


Try Below code.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($_product->getId());
$image= $product->getData('attr_code');
  • i want attribute image not product image
    – imtiaz
    Commented Jan 25, 2019 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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