How can I set an absolute image url for Open Graph Image tags? I need the final tag to look like this:

&lt;meta property="og:image" content="http://mysite.com/uploads/resources/_hero/myimage.jpg"&gt;


If I use something like this:

{% set seoImage = entry.featuredImage.one().getUrl('hero') %}


I end up with a relative URL:

&lt;meta property="og:image" content="/uploads/resources/_hero/myimage.jpg"


So I thought "okay, I'll concatenate the site URL to the front and trim off one of the backslashes":

{% set seoImage = siteUrl ~ entry.featuredImage.one().getUrl('hero')|trim('/', 'left') %}


That worked fine until the server has to generate a new image using image transform. Then we end up, just the once, with a URL that looks like this:

&lt;meta property="og:image" content="http://mysite.com/http://mysite.com/index.php/actions/assets/generate-transform?transformId=46"&gt;"


Darn, No idea what to do from here. Any ideas on how to get an absolute URL for the OG image tag EVERY time?
I'm pretty sure the reason this is happening is because you did not set an absolute Base URL in your asset settings. So if you use /assets/images/folder in your asset settings, that's what the urls will look like on the frontend. If you instead use http://my-project.com/assets/images/folder, your asset urls will include the domain name.



I'd recommend setting up Yii Aliases in your config (if you haven't already) and using those instead of hard-coding the url. So you'd do something like this in Craft's general.php config:

'aliases' =&gt; [
    '@assetBaseUrl' =&gt; 'http://my-project.com/assets',
    '@assetBasePath' =&gt; '/path/to/web/assets',
],


And then in your asset settings you'd be able to use @assetBaseUrl/images/folder instead of http://my-project.com/assets/images/folder. Just a way to keep everything as DRY and clean as possible 



The above solution should solve your issue, but fwiw, I'm pretty sure you can force your site to use absolute urls regardless of your asset settings. If you use the url() method and specify what scheme you want, I believe it will always resolve to an absolute url. So something like the following should work (but it feels very icky to me):

{% set seoImage = entry.featuredImage.one().getUrl('hero') %}
{% set absoluteImageUrl = url(seoImage, '', 'https') %}