I have a custom .phtml file and I want to show a media image attribute within it.
I have the following:
$product = $block->getProduct();
$productImageAttr = $product->getCustomAttribute( 'my_image_attribute' );
$productImage = $this->helper('Magento\Catalog\Helper\Image')
->init($product, 'my_image_attribute')
->setImageFile($productImageAttr->getValue());
and display the image with:
<img src="<?php echo $productImage->getUrl() ?>" alt="<?php echo $block->escapeHtml($product->getTitle()) ?>" />
However the alt tag is blank (even though it is set on the image) and I need to show the width and height of the uploaded image. Can anyone help please?
Many thanks.
Best Answer
Take a look here https://stackoverflow.com/questions/43972344/magento-2-get-height-width-of-image. It's the same question and the second answer it's correct.
Sure, here is the code. I edit the answer to paste the code.