簡體   English   中英

PHP:在共享鏈接中自定義圖像到Facebook

[英]PHP : customize image in share link to facebook

我使用如下腳本來共享指向Facebook的鏈接:

<a class="facebook" href="https://www.facebook.com/sharer/sharer.php?u=&t=" title="Share on Facebook" target="_parent" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(document.URL) + '&t=' + encodeURIComponent(document.URL), 'sharer', 'toolbar=0,status=0,width=548,height=325'); return false;"></a>

只是當彈出窗口分享到Facebook時,圖片太大(根據原始圖像)。 如何設置要最小化的圖像? 例如共享圖片變為200x200時的原始尺寸為700x700圖片。 有什么解決方案?

根據facebook的最佳實踐

圖片大小

使用至少1200 x 630像素的圖像,以在高分辨率設備上獲得最佳顯示效果。 至少應使用600 x 315像素的圖像來顯示具有較大圖像的鏈接頁面帖子。 圖片最大可為8MB。

我們還重新設計了鏈接頁面帖子,以使圖像的寬高比在台式機和移動新聞源中相同。 嘗試使圖像盡可能保持接近1.91:1的縱橫比,以在News Feed中顯示完整圖像,而不會進行任何裁剪。

您還應該檢查開放圖協議 (設置頁面圖像元數據的示例):

<meta property="og:image" content="http://example.com/ogp.jpg" />
<meta property="og:image:secure_url" content="https://secure.example.com/ogp.jpg" />
<meta property="og:image:type" content="image/jpeg" />
<meta property="og:image:width" content="400" />
<meta property="og:image:height" content="300" />
<meta property="og:image:alt" content="A shiny red apple with a bite taken out" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM