How can I echo the url of the image from a page or posts in the header for twittercard or opengraph?

I would just like to point out that theres a good plugin for this that is very powerful. Meta Tags Plugin

If you still want to do it by hand then maybe using the code i used prior to finding the plugin might help… you can add your image stuff to it. Does require a couple of extra blueprint entries to capture SEO title & description and keywords:

<?php if ($page->isHomePage()): ?>

<title><?= $site->seotitle()->html() ?></title>
<meta name="description" content="<?= $site->seometa() ?>">
<meta name="keywords" content="<?= $site->seokeywords() ?>">
<link rel='canonical' href='<?= $site->url() ?>' />
<meta property='og:site_name' content='<?= $site->title()->html() ?>' />
<meta property='og:title' content="<?= html($site->title()) ?>" />
<meta property='og:url' content="<?= $site->url() ?>" />
<meta name='twitter:card' content='summary' />
<meta name='twitter:title' content="<?= html($site->title()) ?>" />
<meta name='twitter:description' content="<?= $site->seometa() ?>" />
<meta name='twitter:url' content="<?= $site->url() ?>" />

<?php else: ?>

<title><?= html($site->seotitle().' | '.$page->seotitle()) ?></title>
<meta name="description" content="<?= $page->seometa() ?>">
<meta name="keywords" content="<?= $page->seokeywords() ?>">
<link rel='canonical' href='<?= $page->url() ?>' />
<meta property='og:site_name' content='<?= $site->title()->html() ?>' />
<meta property='og:title' content="<?= html($site->seotitle().' | '.$page->seotitle()) ?>" />
<meta property='og:url' content="<?= $site->url() ?>" />
<meta name='twitter:card' content='summary' />
<meta name='twitter:title' content="<?= html($site->title().' | '.$page->seotitle()) ?>" />
<meta name='twitter:description' content="<?= $page->seometa() ?>" />
<meta name='twitter:url' content="<?= $page->url() ?>" />

<?php endif ?>