2015-04-04 26 views
0

我很困惑如何去解決我遇到的這個問題。在我的網站上,用戶填寫表單後,會在畫布元素上生成圖像。如何將動態創建的圖片鏈接到Facebook共享中?

這是我希望用戶能夠通過共享對話框在Facebook上分享的圖像。現在我知道如何從canvas轉換爲png,但不是在頁面加載之前。

使用opengraph喜歡這個工作,

<meta property="og:image" content="sample_chart.png" /> 

只有當圖像是現有PNG。一旦用戶到達頁面,似乎沒有辦法將圖像添加到此屬性。

我該怎麼辦?謝謝!

回答

2

如果用戶生成圖像,請將其存儲在您的服務器上,併爲該圖像生成一個唯一的URL,其中包含該頁面的Open Graph標記中圖像的直接URL。

例如,這是網頁的標記怎麼會是這樣的:

<html> 
    <head> 
     <meta property="og:image" content="http://example.com/path/to/image.png" /> 
     <meta property="og:url" content="http://example.com/awesome/image.html" /> 
     <meta property="og:title" content="A title" /> 
     <meta property="og:description" content="A description" /> 
    </head> 
    <body> 
     <img src="http://example.com/path/to/image.png" /> 
    </body> 
</html> 
+0

感謝,這是非常有幫助的。 – user963936 2015-04-09 00:36:58

+1

請注意關於唯一網址的部分非常重要。它不需要是用戶所在頁面的URL。 – Joel 2015-04-10 23:17:31