- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我想了解 offset_y 在 facebooks graph API 中的含义 https://developers.facebook.com/docs/graph-api/reference/cover-photo/ .
我尝试理解这篇相关文章,但不能。 how to compute Facebook graph api cover offset_y to pixel?
例如这个事件。 https://www.facebook.com/events/1119146318216486/ 。调用图形 api 时生成 '"offset_y": 20'
任何帮助将不胜感激,谢谢。
最佳答案
offset_x 和 offset_y 的值是原始图像大小的百分比,而不是像素值。
百分比范围为 0 到 100,并且是调整大小后的图像的空间溢出偏移值的百分比。
例如,我有一个 720x480 像素的图像。封面照片空间为 851x315 像素,因此当调整照片大小以适应该空间时,其大小为 851x567.33 像素。如果我在将图像定位到封面时将该图像向下拖动一半,则返回的 offset_y
将为 50
。这意味着 50% 的“剩余”空间不适合封面照片槽。
“剩余”垂直 (y) 空间将为 567.33 - 315 = 252.33 像素。该空间的 50% 是 126.167。在本例中,我的 top
偏移量将为 -126.167 px。
因此,offset_x
和 offset_y
是将调整大小的图像定位到 Facebook 上的照片空间所需的像素移动的百分比。
// These values retreived ahead of time (Graph API, etc.)
var offset_x = 0;
var offset_y = 50;
var fbCoverPhotoWidth = 851; // Known value, in pixels
var fbCoverPhotoHeight = 315; // Known value, in pixels
// Create an image from the cover photo URL returned by the Graph API
var img = new Image();
img.src = "https://scontent.xx.fbcdn.net/v/t1.0-0/p480x480/your-photo-url-here.jpg";
// Calculate the scaling ratio
var ratio = Math.max(fbCoverPhotoWidth / img.width, fbCoverPhotoHeight / img.height);
// Convert the offset percentages to pixel values
var offset_x_pixels = Math.ceil(((img.width * ratio) - fbCoverPhotoWidth) * (offset_x / 100));
var offset_y_pixels = Math.ceil(((img.height * ratio) - fbCoverPhotoHeight) * (offset_y / 100));
console.log(offset_x_pixels);
console.log(offset_y_pixels);
关于Facebook 图形 API : offset_y offset_x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47238129/
您好,我想了解 offset_y 在 facebooks graph API 中的含义 https://developers.facebook.com/docs/graph-api/reference
您好,我想了解 offset_y 在 facebooks 图形 API 中的含义 https://developers.facebook.com/docs/graph-api/reference/co
例如,我可以从 graph api 中检索 facebook 封面来源和 offset_y - https://graph.facebook.com/Inna 我明白了- "cover": {
我是一名优秀的程序员,十分优秀!