1

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?

  • In you theme etc/view.xml find image id product_base_image and check the image type, if this select image id that type will be image, if type is small_image change to image If type is image only then respective size (width & height) will 80*80 change that one to a proper size as you required. and flush cache and check respective product detail page. – Kanhaiya lal Apr 22 '18 at 16:56
  • What is the file path of the xml that you're talking about Kanhaiya? – YorkieMagento Dec 21 '18 at 15:11
1

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; ?>" />
  • Does this just increase the small image size (i.e. won't it lose resolution)? – YorkieMagento Dec 21 '18 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.