How is \Magento\Catalog\Block\Product\ImageBuilder implemented and used?

Implementation

\Magento\Catalog\Block\Product\ImageBuilder::create()

/**
 * Create image block
 *
 * @return \Magento\Catalog\Block\Product\Image
 */
public function create()
{
	/** @var \Magento\Catalog\Helper\Image $helper */
	$helper = $this->helperFactory->create()
		->init($this->product, $this->imageId);

	$template = $helper->getFrame()
		? 'Magento_Catalog::product/image.phtml'
		: 'Magento_Catalog::product/image_with_borders.phtml';

	$imagesize = $helper->getResizedImageInfo();

	$data = [
		'data' => [
			'template' => $template,
			'image_url' => $helper->getUrl(),
			'width' => $helper->getWidth(),
			'height' => $helper->getHeight(),
			'label' => $helper->getLabel(),
			'ratio' =>  $this->getRatio($helper),
			'custom_attributes' => $this->getCustomAttributes(),
			'resized_image_width' => !empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth(),
			'resized_image_height' => !empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight(),
		],
	];

	return $this->imageFactory->create($data);
}

Usage

1. \Magento\Catalog\Block\Product\AbstractProduct::getImage()

2. \Magento\Checkout\Block\Cart\Item\Renderer::getImage()

3. \Magento\GiftMessage\Block\Message\Inline::getImage()

4. \Magento\ProductAlert\Block\Email\AbstractEmail::getImage()

See also: