I need to generate an email template with product image included in it, i need to check if the product image exist or not , if product image not exist i want to generate magento 2 default product image thumbnail with custom size, now i'm generating custom size product image with this:
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($data['item_id']);
$imageHelper = $objectManager->get('\Magento\Catalog\Helper\Image');
$width = 150; $height = 150;
$imageUrl = $imageHelper->init($product,'product_page_image_small')->setImageFile($product->getFile())->resize($width,$height)->getUrl();
echo $imageUrl;
because the product doesn't have image it produce url like this:
http://test.com/pub/static/version1496373583/adminhtml/Magento/backend/en_US/Magento_Catalog/images/product/placeholder/.jpg