I'm getting image for Open Graph protocol with following code:

<meta property="og:image" content="<?php echo $block->escapeUrl($block->getImage($block->getProduct(), 'product_base_image')->getImageUrl()); ?>" />

But it gives me the small image with 80x80px size:

<meta property="og:image" content="https://example.com/pub/media/catalog/product/cache/image/80x80/beff4985b56e3afdbeabfc89641a4582/0/1/01.jpg">

Now I have such folder structure:

enter image description here

How can I get the other size from this folder or non cached images?

有帮助吗?

解决方案

Try the following code:

<?php
$imagehelper = $this->helper('Magento\Catalog\Helper\Image');
$ogImage = $imagehelper->init($block->getProduct(), 'product_base_image')
                       ->constrainOnly(FALSE)
                       ->keepAspectRatio(TRUE)
                       ->keepFrame(FALSE)
                       ->resize(250, 250)
                       ->getUrl();
?>

<meta property="og:image" content="<?php echo $ogImage; ?>" />
许可以下: CC-BY-SA归因
scroll top