magento 2 get product image

use Magento\Framework\App\ObjectManager;
use Magento\Framework\View\Element\Template;
use Magento\Catalog\Model\Product;

class myClass extends Template
{	
	/**
	 * @param \Magento\Catalog\Model\Product $product
	 * @return \Magento\Catalog\Block\Product\Image
	 */
	public function getProductImage(Product $product){
		$objectManager =\Magento\Framework\App\ObjectManager::getInstance();
		/** @var \Magento\Catalog\Block\Product\ImageBuilder $imageBuilder */
		$imageBuilder = $objectManager->create(\Magento\Catalog\Block\Product\ImageBuilder::class);
		return $imageBuilder->create($product, 'category_page_grid');
	}
}

// in phtml use
<?=$block->getProductImage($product)?>


3.86
7
Perigord 105 points

                                    //todo get product object $product 

$objectManager =\Magento\Framework\App\ObjectManager::getInstance();
$helperImport = $objectManager-&gt;get('\Magento\Catalog\Helper\Image');

$imageUrl = $helperImport-&gt;init($product, 'product_page_image_small')
                -&gt;setImageFile($product-&gt;getSmallImage()) // image,small_image,thumbnail
                -&gt;resize(380)
                -&gt;getUrl();
echo $imageUrl;

3.86 (7 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
get product category page image magento 2 magento 2 product image location magento 2 get product data get all image in product page magento 2 get all product image in magento 2 magento 2 get product sources where are product images stored in magento 2 magento2 assign product image from media magento 2 add product image programmatically order get product image in cart magento 2 magento 2 get product count images get product main image magento 2 image product requirement magento 2 magento 2 how to get product second image get product in magento 2 magento 2 set product image programmatically magento 2 add product image programmatically update image product magento 2 magento 2 get product magento2 get product collection with image magento 2 get product collection where image thumbnail not upload magento 2 get all product where product image is available magento 2 get Product() magento 1 get images by product id product get magento 1 magento 2 get image of product configuration magento 2 product image per store view magento 2 product image per store magento 2 product page images Magento 2.4 product Image helper Product Review Images magento 2 magento 2 get product html magento 2 product images magento 2 get product with images magento 2 get product collection with images magento 2 get product image url from collection magento import product images magento 2 import product images programmatically magento2 query get images of a product load all product images in magento 2 get product images from magento api magento 2 add image to product programmatically magento 2 $product image url magento2 get product image magento 2 product image id magento 2 get product image in phtml magento 2 product get thumbnail Magento 2 Product Image Import magento 2 get image from product magento 2 in current product images magento get backend product data find product api magento get all product image magento 2 get product image url magento 2 magento2 get image product php magento2 product images php magento 2 get product image api magento 2 in product id by image magento 2 in product name using get image magento 2 in object manager using product by get image magento 2 product image folder magento 2 product image path get configurable product image in magento 1.9 get image product magento 2 get product image from product repository in magento 2 magento 1 product images magento get product image url magento 1 get product images magento get product images get product image in magento 2 magento 2 get product main image magento 2 get product thumbnails get product all image in magento1 magento 2 get product images magento 2 get product image object manager how to reduce the product image on the product page in magento 2 magento 2 add image attribute to category magento 2 $product-&gt;getImage() magento 2 product getimage $product-&gt;getData('thumbnail'); get image url product magento 2 get product image magento 2 how to get product image url in magento 2 How to get product image useing collection in Magento 2 How to get product image collection in Magento 2 magento 2 product get image get all product images magento 2 product get image full url magento 2 in product id using get image how to add images to products magento Magento ver. 1.7.0.2 magento 2 get product image url in phtml magento2 getImageProduct magento 2 get image by product id in phtml magento 2 get image by product id magento 2 get image magento 2 get product image by id $order-&gt;get_order_image_url() get image magento 2 product image url get image url of product in magento2 get image url magento 2 maegtno 2 get image magento 2 get product image in block magento 2 get product image url get an image in magento 2 html Unterminated RegEx at byte 182: thumbnail url magento 2 getImageUrl magento 2 magento 2 get product thumbnail image url magento 2 in product id using get the image magento2 helper get product image magento 2 set image product from api get product image url in magento 2 magneot 2 js mage/url get cart url magento 2 in product id using getnthe image get ikmag url in product list magento 2 magento 2 get product image html magento 2 get product image
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source