Keyword

Og:image Width and Height

  • mjmartino
  • mjmartino's Avatar Topic Author
  • Offline
  • Senior Member
More
4 years 5 months ago #173661 by mjmartino
Og:image Width and Height was created by mjmartino
Hi Fortis
Could you add in new version meta tag og:image
Meta Tag <meta property="og:image:width" content="1200" />
Meta Tag <meta property="og:image:height" content="600" />
If facebook not found this tag og:image with width and height image is not grab the first time. The workaround is to add the link a second time, then FB downloads the image, but it is annoying.

Regards :)

Please Log in or Create an account to join the conversation.

More
4 years 5 months ago #173668 by JoomlaWorks
Replied by JoomlaWorks on topic Og:image Width and Height
I'm not aware of such an issue (and we deal with large news sites daily - so I'd know for sure).

Plus, to add automatic width/height values means PHP would work to read an image's dimensions using GD, which is wasted CPU resources really...

In any case, it's easy for you to override any K2 meta tag directly from your K2 template overrides. Inside your item.php override, add this at the top of the file (after <?php):
<?php

// no direct access
defined('_JEXEC') or die;

// Get the image and its dimensions
if($this->item->params->get('itemImage') && !empty($this->item->image) {

    $basename = basename($this->item->image);
    if (strpos($basename, '?t=')!==false) {
        $tmpBasename = explode('?t=', $basename);
        $basenameWithNoTimestamp = $tmpBasename[0];
    } else {
        $basenameWithNoTimestamp = $basename;
    }

    $imagePathOnSystem = JPATH_SITE.'/media/k2/items/cache/'.$basenameWithNoTimestamp;

    if (JFile::exists($imagePathOnSystem)) {
        list($width, $height) = getimagesize($imagePathOnSystem);

        $document = JFactory::getDocument();
        $document->setMetaData('og:image:width', $width);
        $document->setMetaData('og:image:height', $height);
    }
}

Easy-peasy with K2 :)

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • mjmartino
  • mjmartino's Avatar Topic Author
  • Offline
  • Senior Member
More
4 years 5 months ago #173684 by mjmartino
Replied by mjmartino on topic Og:image Width and Height
Thank for quick answer and solution.
I will test it.

Please Log in or Create an account to join the conversation.

  • mjmartino
  • mjmartino's Avatar Topic Author
  • Offline
  • Senior Member
More
4 years 5 months ago - 4 years 5 months ago #173702 by mjmartino
Replied by mjmartino on topic Og:image Width and Height
I don't whre is error find but
syntax error, unexpected '{'
Last edit: 4 years 5 months ago by mjmartino.

Please Log in or Create an account to join the conversation.

More
4 years 5 months ago #173709 by JoomlaWorks
Replied by JoomlaWorks on topic Og:image Width and Height
Change to:
<?php

// no direct access
defined('_JEXEC') or die;

// Get the image and its dimensions
if($this->item->params->get('itemImage') && !empty($this->item->image)) {

    $basename = basename($this->item->image);
    if (strpos($basename, '?t=')!==false) {
        $tmpBasename = explode('?t=', $basename);
        $basenameWithNoTimestamp = $tmpBasename[0];
    } else {
        $basenameWithNoTimestamp = $basename;
    }

    $imagePathOnSystem = JPATH_SITE.'/media/k2/items/cache/'.$basenameWithNoTimestamp;

    if (JFile::exists($imagePathOnSystem)) {
        list($width, $height) = getimagesize($imagePathOnSystem);

        $document = JFactory::getDocument();
        $document->setMetaData('og:image:width', $width);
        $document->setMetaData('og:image:height', $height);
    }
}

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum