Calculate the facebook cover offset y

限于喜欢 提交于 2019-12-11 03:27:50

问题


I'm getting the user cover photo using Facebook SDK. I have the path to the img and the offset y.

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

The div where i put the image have 300px height; and right background position is center -146px;. How to calculate the top value when I have 300 and 19 ?


回答1:


offset_y is a proportion of space between upper area and lower area of cropped image.

So, actual pixel offset should be like this:

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

Edited:

// 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


来源:https://stackoverflow.com/questions/11812364/calculate-the-facebook-cover-offset-y

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!