问题
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