方形 Facebook 图片
使用 Graph API 我可以获得小、大、中的图片。或者我可以得到小正方形图片。
但是怎样才能得到大的正方形图片呢?有什么服务我可以使用吗?
Using Graph API I can get small, large, medium pictures. Or I can get small square picture.
But how can I get large square picture? Is there any service I can use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
很简单,我刚刚发现这个。
例如,
https://graph.facebook.com/friends_Id/picture?width=200&height= 200多多
~
Simple, I just found this out.
Example,
https://graph.facebook.com/friends_Id/picture?width=200&height=200
tada~
奇怪的是,Facebook 本身并没有使用更大的方形图像,尽管他们在新的时间轴图片上显示了更大的方形个人资料图片。如果您仔细观察,他们会采用更大的矩形图像并将其重新定位在 HTML 元素内,如 Michael 上面建议的那样。
我预计在某个时候他们使用的定位数据将通过 API 发布,但我不知道该数据是否可用。我曾经有过这样的经历,这也会很有帮助,到目前为止,要么只是将图像居中,要么使用顶部部分。但这并不理想,因为 FB 已经允许通过其“图标”创建者来允许并跟踪图像中最重要的“方块”的自定义定位。
Oddly enough, Facebook itself doesn't use a bigger square image even though they show a bigger squared profile picture on the new timeline pictures. If you take a closer look they take a larger rectangular image and reposition it inside an HTML element as Michael proposed above.
I would expect that at some point the positioning data they use for this will be released via the API but I am not aware of that data being available yet. I've had times where this would have been helpful also and have thus far either just centered the image or used the top portion. Not ideal though since FB already allows for and tracks custom positioning of the most important "square" of the image via their "icon" creator.
官方没有办法做到这一点,这里有一个愚蠢的技巧。以下代码将确保图像的宽度/高度不超过 120 像素。如果是,那么图像将溢出到元素之外:
There is no way to do this officially, here's a silly hack. The following code will make sure the image is no wider/taller than 120 pixels. If it is, then the image will overflow outside the element:
来自图形 API 参考。这是仅有的三种尺寸。您可以使用更大版本的 50x50 图像,但它显然会看起来抖动。
From the Graph API Reference. Those are the only three sizes available. You can use a bigger version of the 50x50 image but it'll obviously look dithered.
如今,Graph 实际上可以返回任何大小的方形图像。它们缓存最常见的尺寸(例如 100x100、128x128),并通过以下 请求(悬停查看)
Nowadays Graph actually could return you square image of any size. They cache most common sizes (like 100x100, 128x128) and return the closest size by the following request (hover to see)
正如其他答案已经指出的那样,在 facebook 中,方形图片仅具有
50x50
分辨率。一个简单的 CSS hack 就可以解决这个问题:
查询大图像,用
div
包装img
-标签,并将此 CSS 应用于 div:If
YOUR_WIDTH< /code> 和
YOUR_HEIGHT
与您获得的方形图像相同,并且比例被保留。As the other answers already stated, in facebook the square pictures are only in
50x50
resolution.A simple CSS hack does the trick though:
Query the large image, wrap the
img
-tag with adiv
and apply this CSS to the div:If
YOUR_WIDTH
andYOUR_HEIGHT
are the same you get your square image and the ratio is preserved.没有一个答案对我来说是完美的,因为我遇到了各种尺寸的个人资料图片(有些高度比预期更高,有些高度较小),最终要么被拉伸,要么不居中。
最后我使用了
div
元素而不是img
并通过background-image
style
设置图像属性而不是通过其 src 属性。CSS 文件:
HTML:
将上面的 120px(在 CSS 中出现两次,在 HTML 片段中出现两次)替换为您想要的尺寸。
None of the answers worked perfectly for me, having come across profile pictures of various dimensions (some with a greater height than expected, some with a smaller height) which ended up either stretched or non-centered.
In the end I used a
div
element instead of animg
and set the image through abackground-image
style
attribute rather than through itssrc
attribute.CSS file:
HTML:
Replace 120px in the above (occurs twice in the CSS and twice in the HTML fragment) with your desired dimensions.