计算Facebook封面偏移量y

时间:2012-08-04 22:14:20

标签: facebook facebook-timeline

我正在使用Facebook SDK获取用户封面照片。我有img和偏移y的路径。

  "source": "http://a5.sphotos.ak.fbcdn.net/hphotos-ak-ash3/526114_459046674110601_992101492_n.jpg",
  "offset_y": 19

我放置图像的div高度为300px;右侧背景位置为center -146px;。当我有300和19时如何计算top value

1 个答案:

答案 0 :(得分:0)

offset_y是裁剪图像上部区域和下部区域之间的空间比例。

因此,实际的像素偏移应该是这样的:

y = (offset_y / 100) * (upperArea_of_cropImage.height + lowerArea_of_cropImage.height)

编辑:

// where y is the actual pixels from the upper left corner of the real image to
// upper left corner of the cropped image

        -- ================================  --
    y {   ||                              ||    } a
        --||..............................|| --
          ||                              ||
          ||                              ||
          ||            Cover             ||
          ||                              ||
          ||..............................|| --
          ||                              ||    } b
          ||                              ||   |
           ================================  --

     offset_y that Facebook send to you actually was a/b not y