13

I have image that is being generated in runtime on my website and I display it in html using

<img src="data:image/jpeg;base64,<!-- base64 data -->" />

Now, I want for Facebook to fetch this image, but if I do the same for og:image meta tag, facebook debugger gives me an error. Any solution?

<meta property='og:image' content='data:image/jpeg;base64,<!-- base64 data -->'/>

Of course, I would like to avoid permanent saving of files since they are always different and it would get too crowded very quickly

Eric
  • 95,302
  • 53
  • 242
  • 374
Vuk Stanković
  • 7,864
  • 10
  • 41
  • 65

2 Answers2

14

Paste it to a PHP file that echos it out:

    <meta property='og:image' content='decoder.php?data=<!-- base64 data -->'/>

decoder.php:

    <?php
        echo base64_decode($_GET['data']);
    ?>

EDIT Make sure you check source for security reasons.

Nathan Dai
  • 392
  • 2
  • 11
exim
  • 606
  • 1
  • 8
  • 24
  • this seems like good solution. Just one question. Won't the url for decoder.php be too long? – Vuk Stanković Aug 27 '13 at 08:38
  • shouldn't be problem in new browsers (and for fb!) – exim Aug 27 '13 at 10:17
  • 2
    @exim I have the following error: 414 (Request-URI Too Large) – neoDev May 31 '15 at 02:43
  • @neoDev Yep, I'm getting 414 too: http://stackoverflow.com/questions/2891574/how-do-i-resolve-a-http-414-request-uri-too-long-error (hint: use smaller images or change server configuration) – Mars Robertson Oct 06 '15 at 16:17
  • @AugustinRiedinger just change the endpoint to a nodeJS endpoint. The language isn't important, it is just doing a get request. This is highly inefficient, but an interesting solution. – Frank Robert Anderson Oct 02 '18 at 17:38
4

Open Graph needs an URL.

You could try saving your base64 as a temp image.

Gerben Jacobs
  • 4,515
  • 3
  • 34
  • 56