You want to bring image_with_borders.phtml template file into your theme.
https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Catalog/view/frontend/templates/product/image_with_borders.phtml
Then it's something like this
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>
<?php /** @var $block \Magento\Catalog\Block\Product\Image */ ?>
<span class="product-image-container"
style="width:<?= $block->escapeHtmlAttr($block->getWidth()) ?>px;">
<span class="product-image-wrapper"
style="padding-bottom: <?= ($block->getRatio() * 100) ?>%;">
<img class="<?= $block->escapeHtmlAttr($block->getClass()) ?>"
<?= $block->escapeHtmlAttr($block->getCustomAttributes()) ?>
src="<?= $block->escapeUrl($block->getImageUrl()) ?>"
max-width="<?= $block->escapeHtmlAttr($block->getWidth()) ?>"
max-height="<?= $block->escapeHtmlAttr($block->getHeight()) ?>"
alt="<?= /* @noEscape */ $block->stripTags($block->getLabel(), null, true) ?>
title="<?= /* @noEscape */ $block->stripTags($block->getLabel(), null, true) ?>"/></span>
</span>
Uses image label. But that might be safer?
But if you want product name try
$block->getProduct()->getName();
but if that doesnt work
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('product');
$name = $product ? $product->getName() : null;
Which isn't perfect but close enough.
The better solution would be to modify Magento\Catalog\Block\Product\Image in an extension and then inject registry
https://blog.qaisarsatti.com/magento_2/magento-2-get-current-product-information/