2013-08-01 46 views

回答

0

圖形API不會根據寬度和高度返回圖像的大小。 但是,您可以指定大小,你想用「高度」和檢索「寬度」參數,如:

me/picture?width=70&height=90 

此外,還有一些默認的大小,你可以檢索使用「類型」參數: https://developers.facebook.com/docs/reference/api/using-pictures/#sizes

最後,您可以檢索任意大小的圖片並以編程方式獲取其寬度和高度。

javascript例子:

現代瀏覽器和IE9 +:

var width = document.getElementById('yourImg').naturalWidth, 
    height = document.getElementById('yourImg').naturalHeight; 
console.log(width, height); 

對於IE8-:

var img = new Image(), // or document.createElement('img') 
    width, 
    height; 

img.onload = function() { 
    width = this.width; 
    height = this.height; 
}; 

img.src = 'http://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/626_someid_202729_q.jpg' 
console.log(width, height); 
+0

的事情是瞭解寬度和高度_before_頁面早餐。我需要爲標籤定義寬度和高度屬性以避免頁面痙攣。 –

+0

在請求之前和之後設置的寬度和高度屬性有什麼區別? –

+0

設置高度屬性時,整個頁面在加載圖像前後具有相同的固定高度。否則元素具有零高度和寬度,直到瀏覽器知道尺寸。這會導致互聯網連接速度變慢。 –