简体   繁体   English

PHP:在共享链接中自定义图像到Facebook

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

I use a script like the following to share links 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>

it's just when pop up share to facebook, the picture is too big (according to the original image). 只是当弹出窗口分享到Facebook时,图片太大(根据原始图像)。 How to set the image to be minimized? 如何设置要最小化的图像? for example the original size of 700x700 image .. when shared image becomes 200x200. 例如共享图片变为200x200时的原始尺寸为700x700图片。 what's the solution ? 有什么解决方案?

According to facebook best practices : 根据facebook的最佳实践

Image Sizes 图片大小

Use images that are at least 1200 x 630 pixels for the best display on high resolution devices. 使用至少1200 x 630像素的图像,以在高分辨率设备上获得最佳显示效果。 At the minimum, you should use images that are 600 x 315 pixels to display link page posts with larger images. 至少应使用600 x 315像素的图像来显示具有较大图像的链接页面帖子。 Images can be up to 8MB in size. 图片最大可为8MB。

We've also redesigned link page posts so that the aspect ratio for images is the same across desktop and mobile News Feed. 我们还重新设计了链接页面帖子,以使图像的宽高比在台式机和移动新闻源中相同。 Try to keep your images as close to 1.91:1 aspect ratio as possible to display the full image in News Feed without any cropping. 尝试使图像尽可能保持接近1.91:1的纵横比,以在News Feed中显示完整图像,而不会进行任何裁剪。

You should also check the open graph protocol , the example of setting page image metadata: 您还应该检查开放图协议 (设置页面图像元数据的示例):

<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