2

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 ?

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Marian Petrov
  • 625
  • 2
  • 9
  • 21
  • I really need help for this also. I got the same issue. I have offset_y 47 from FACEBOOK, and approx top -223 to fit the same image inside the div. The height of the div is 200px – FooBar Oct 09 '13 at 22:52

1 Answers1

0

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
myLifeasdog
  • 1,959
  • 2
  • 13
  • 11
  • Would you mind explaining how to use the offset? I'm not sure I understand how knowing the proportion between the areas will help me find the top Y value of the cropped image. Where do I get the upper/lowerArea_of_cropImage? Thank you! – Gerardo Contijoch Jan 29 '13 at 16:38
  • I really need help for this also. I got the same issue. I have offset_y 47 from FACEBOOK, and approx top -223 to fit the same image inside the div. The height of the div is 200px. – FooBar Oct 09 '13 at 22:53
  • I edited my Answer. (Maybe this is very very too late and Facebook maybe changed their APIs but just incase.) – myLifeasdog Jun 10 '14 at 11:58