get thumbnail image in product collection magento 2.3 but base image get how to get thumbnail image

phtml file

            $ProductImageUrl = $block->getUrl('pub/media/catalog').'product'.$product->getImage();
        <a class="productlinks" href="" title=""><img src="<?php echo $ProductImageUrl; ?>" width="210" height="210">

Block File

protected $_productCollectionFactory;

public function __construct(
   \Magento\Catalog\Block\Product\Context $context, 
   \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
array $data = []
       $this->_productCollectionFactory = $productCollectionFactory;    
       parent::__construct($context, $data);

public function getProductCollection()
    $collection = $this->_productCollectionFactory->create();
    $collection->addFieldToFilter('entity_id', array('in' => $porIds));
    return $collection;
  • Share your collection code?
    – Amit Bera
    Aug 25, 2020 at 7:06
  • check block.php file @Amit Bera Aug 25, 2020 at 7:28

3 Answers 3


Use Magento\Catalog\Helper\Image in your block to get the thumbnail image of product

public function getImageUrl($product) {
    $this->imageHelper->init($product, 'product_thumbnail_image')->getUrl();

1.add below in phtml file, it is based on the \Magento\Catalog\Block\Product\ListProduct

$imageDisplayArea = 'your_custom_img_id';
$productImage = $block->getImage($product, $imageDisplayArea);
//$position = 'left:' . $productImage->getWidth() . 'px;'. 'top:' . $productImage->getHeight() . 'px;';

<a href="<?= $escaper->escapeUrl($product->getProductUrl()) ?>"
        class="product photo product-item-photo"
        <?= $productImage->toHtml() ?>
  1. Go to theme file app/design/frontname/Namespace/ThemeName/etc/view.xml

add any custom image id under <images module="Magento_Catalog"> something like below with type = thumbnail with own width and height:

<view ......>
        <images module="Magento_Catalog">
<image id="your_custom_img_id" type="thumbnail">

make sure <image id="your_custom_img_id" and $imageDisplayArea = 'your_custom_img_id'; both should have same value.

if changes are not reflected then you resize images using php bin/magento catalog:images:resize


phtml File

  $ProductImageUrl = $block->getUrl('pub/media/catalog').'product'.$product->getData('thumbnail');

 <a class="productlinks" href="#" title=""><img src="<?php echo $ProductImageUrl; ?>" width="210" height="210">

Your Answer

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

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