方形 Facebook 图片

发布于 2024-11-03 19:05:31 字数 86 浏览 1 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

心在旅行 2024-11-10 19:05:31

奇怪的是,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.

潦草背影 2024-11-10 19:05:31

官方没有办法做到这一点,这里有一个愚蠢的技巧。以下代码将确保图像的宽度/高度不超过 120 像素。如果是,那么图像将溢出到元素之外:

<div style="width: 120px; height: 120px; overflow: hidden; display: inline-block;">
    <img src="{$image}" align="absmiddle" width=120 style="min-width: 120px; min-height: 120px;" />
</div>

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:

<div style="width: 120px; height: 120px; overflow: hidden; display: inline-block;">
    <img src="{$image}" align="absmiddle" width=120 style="min-width: 120px; min-height: 120px;" />
</div>
韬韬不绝 2024-11-10 19:05:31

您可以使用 type 参数指定所需的图片尺寸,该尺寸应为正方形 (50x50)、小(50 像素宽,可变高度)和大(约 200 像素宽,可变高度)之一。

来自图形 API 参考。这是仅有的三种尺寸。您可以使用更大版本的 50x50 图像,但它显然会看起来抖动。

You can specify the picture size you want with the type argument, which should be one of square (50x50), small (50 pixels wide, variable height), and large (about 200 pixels wide, variable height).

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.

哑剧 2024-11-10 19:05:31

如今,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)

为你拒绝所有暧昧 2024-11-10 19:05:31

正如其他答案已经指出的那样,在 facebook 中,方形图片仅具有 50x50 分辨率。

一个简单的 CSS hack 就可以解决这个问题:

查询大图像,用 div 包装 img-标签,并将此 CSS 应用于 div:

img#facebook_img {
 width: YOUR_WIDTH;
}
div#wrapper {
 height: YOUR_HEIGHT;  
 overflow: hidden;  
}

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 a div and apply this CSS to the div:

img#facebook_img {
 width: YOUR_WIDTH;
}
div#wrapper {
 height: YOUR_HEIGHT;  
 overflow: hidden;  
}

If YOUR_WIDTH and YOUR_HEIGHT are the same you get your square image and the ratio is preserved.

听,心雨的声音 2024-11-10 19:05:31

没有一个答案对我来说是完美的,因为我遇到了各种尺寸的个人资料图片(有些高度比预期更高,有些高度较小),最终要么被拉伸,要么不居中。

最后我使用了 div 元素而不是 img 并通过 background-image style 设置图像属性而不是通过其 src 属性。

CSS 文件:

.profile-pic {
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    height: 120px;
    width: 120px;
    border: solid 1px #ddd;
}

HTML:

 <div style="background-image:url(https://graph.facebook.com/123/picture?width=120&height=120);" class="profile-pic"></div>

将上面的 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 an img and set the image through a background-image style attribute rather than through its src attribute.

CSS file:

.profile-pic {
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    height: 120px;
    width: 120px;
    border: solid 1px #ddd;
}

HTML:

 <div style="background-image:url(https://graph.facebook.com/123/picture?width=120&height=120);" class="profile-pic"></div>

Replace 120px in the above (occurs twice in the CSS and twice in the HTML fragment) with your desired dimensions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文