I want get the user profile large or normal picture from facebook. Now I get the square version from user profile picture with this code:
:image => access_token.info.image
# http://graph.facebook.com/id/picture?type=square
How can I get the large or normal versions?
Or and the app, How can I replace in this url the last word, large instead square...
Thank you very much!
If you want to grab a different size picture at login time, the omniauth-facebook strategy has an option to change which picture is requested.
image_size: Set the size for the returned image url in the auth hash.
For example, the large picture would be requested in omniauth.rb this way:
provider :facebook, 'secrets', 'sekrets', :image_size => 'large'
https://github.com/mkdynamic/omniauth-facebook#configuring
Below are the 4 Different Size of profile pictures that is allowed by facebook.
http://graph.facebook.com/id/picture?type=small http://graph.facebook.com/id/picture?type=square http://graph.facebook.com/id/picture?type=large http://graph.facebook.com/id/picture?type=normal
When you save it into the DB you could do it like this access_token.info.image.split("=")[0] << "=large"
and just change large to whatever size you want.
Or you could have a helper method for displaying different sizes in your views.
def profile_photo(type="large")
puts @user.image.split("=")[0] << "=#{type}"
end
profile_photo("small") #=> http://url?type=small
profile_photo("square") #=> http://url?type=square
profile_photo #=> http://url?type=large
profile_photo("normal") #=> http://url?type=normal
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With