How can I get product image and product url from item? That’s the way I did. it’s quite efficient and clean:

1) First, you need to inject the following classes:

protected $_storeManager;
 protected $_appEmulation;
 protected $_blockFactory;

public function __construct(
 ...
 \Magento\Store\Model\StoreManagerInterface $storeManager,
 \Magento\Framework\View\Element\BlockFactory $blockFactory,
 \Magento\Store\Model\App\Emulation $appEmulation)
 {
 $this->_storeManager = $storeManager;
 $this->_blockFactory = $blockFactory;
 $this->_appEmulation = $appEmulation;
 }

2) Then, create a getImageUrl method with the code below:

protected function getImageUrl($product, string $imageType = '')
 {
 $storeId = $this->_storeManager->getStore()->getId();

$this->_appEmulation->startEnvironmentEmulation($storeId, \Magento\Framework\App\Area::AREA_FRONTEND, true);

$imageBlock = $this->_blockFactory->createBlock('Magento\Catalog\Block\Product\ListProduct');
 $productImage = $imageBlock->getImage(product, $imageType);
 $imageUrl = $productImage->getImageUrl();

$this->_appEmulation->stopEnvironmentEmulation();

return $imageUrl;
 }

Note: The “appEmulation” code is only necessary when you making this call from the admin or for an API. Otherwise, you will get the error below (or similar):

Unable to resolve the source file for 'webapi_rest/_view/en_AU/Magento_Catalog/images/product/placeholder/.jpg'

3) Call the getImageUrl passing the product object and the type of image you want (based on your view.xml file)

...
 $smallImage = $this->getImageUrl($productObject, 'product_page_image_small');
 ...

Happy coding!

How to get product image url in Magento 2https://i2.wp.com/blog.mdnsolutions.com/wp-content/uploads/2016/06/Screen-Shot-2016-06-24-at-10.49.47-AM.png?fit=768%2C391&ssl=1https://i2.wp.com/blog.mdnsolutions.com/wp-content/uploads/2016/06/Screen-Shot-2016-06-24-at-10.49.47-AM.png?resize=150%2C150&ssl=1Renato MedinaMagentoMagento 2Get Image Url,Magento 2,ProductHow can I get product image and product url from item? That's the way I did. it's quite efficient and clean: 1) First, you need to inject the following classes: protected $_storeManager; protected $_appEmulation; protected $_blockFactory; public function __construct( ... \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\View\Element\BlockFactory $blockFactory, \Magento\Store\Model\App\Emulation $appEmulation) { $this->_storeManager = $storeManager; $this->_blockFactory =...A Magento Craftsman in Melbourne