offset_x
和offset_y
的值是原始圖像大小的百分比,而不是像素值。
百分比範圍從0到100,並且是空間大小調整圖像的溢出偏移值的百分比。
例如,我有一個圖像是720x480像素。封面照片空間是851x315像素,所以當照片的大小適合這個空間時,它是851x567.33像素。如果我將該圖像放置在一半的位置時將其拖到我的封面上,則返回的offset_y
將爲50
。這意味着50%的「剩餘」空間不適合封面照片插槽。
「剩餘」垂直(y)空間將是567.33 - 315 = 252.33 px。該空間的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);
,其他問題你指的是五歲。文件似乎比現在更明確地表明瞭這個價值實際上意味着什麼。如果有的話,我會用它作爲嘗試理解它的起點。 (但是,從目前爲止所有問題都可以看出,整個事情似乎或多或少都是一個謎,沒有人有太多的運氣來理解它,或者實際上將它應用於實際的用例中[什麼是你的,順便說一句],太好運了;-) – CBroe