FB 个人资料图片总是返回为“.jpg”?
尝试通过 Facebook 社交图谱提取用户图像。
奇怪的是,无论我上传图像是什么(gif、bmp、tiff 或 jpg),我都会调用 https://graph.facebook.com/507988137/picture?type=large(我的图片)始终返回 jpg。
有谁知道我是否可以假设他的图像始终是“jpg”?我正在使用 php get_file_contents 来提取图像和我宁愿不必对它们进行各种格式的嗅探测试。
Trying to pull user images via the Facebook Social Graph.
Finding it odd that no matter what I upload the image as (gif, bmp, tiff, or jpg), my call to https://graph.facebook.com/507988137/picture?type=large (my pic) always returns a jpg.
Does anyone know if I'm OK assuming that his image is always a "jpg"? I'm using php get_file_contents to pull the images & would prefer not having to sniff test them for various formats.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是因为 Facebook 将其存储为 jpg,因为这通常是最有效的图片图像格式。
检查数据是否符合您的预期总是一个好主意。检查图像类型非常容易。它始终是一种 Web 格式,基本上可以归结为 jpg、png 和 gif,其中 gif 由于其局限性而不太可能出现(GIF 最多可以包含 256 种颜色,并且通常比 png 更大。也有许可证限制)。
BMP 不是网页格式,无法在大多数浏览器中显示。您不会从该 url 获得 BMP。
That's because FaceBook stores it as a jpg, because that is in general the most efficient image format for pictures.
It's always a good idea to check if the data is what you expect. Checking image type is quite easy. It will always be a web format, which basically comes down to jpg, png and gif, with gif being very unlikely because of its limitations (GIF can contain 256 colors at most, and is generally larger than png. Has license limitations too).
BMP is not a web format and cannot be displayed in most browsers. You will not get a BMP from that url.
确保您也处理了 gif 返回给您的情况。
这是不更新个人资料图片的用户的默认个人资料图片
make sure you also handle the case where a gif is returned to you.
This is the default profile pic for users that doesn't update their profile pic
Facebook 不会保存您上传的原始图像。相反,它将所有上传的图像转换为 4 种不同尺寸的 jpg,以支持可能显示图像的所有不同位置。
如果你感兴趣的话,Facebook 基本上把这归结为一门科学,事实上,我已经读过好几次了,他们是世界上最大的图像托管服务。有关更多详细信息,请参阅这篇 Facebook 博客文章 Facebook 照片基础架构
Facebook doesn't save the original image that you upload. Instead it converts all uploaded images to jpgs of 4 different sizes to support all the different places where the image may be displayed.
In case you are interested, Facebook basically has this down to a science, in fact, I've read several times that they are the largest image hosting service in the world. More details within this Facebook blog post, Facebook Photos Infrastructure