23

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!

hyperrjas
  • 10,666
  • 25
  • 99
  • 198

4 Answers4

33

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

Derek Lucas
  • 488
  • 7
  • 15
  • 2
    Thank you I have checked this fix for me in my devise.rb file but it does not works fine for me :(. I received square version. I am using devise 2.0 with omniauth-facebook (1.2.0) gem! – hyperrjas Jun 08 '12 at 09:13
  • 1
    This IS the proper answer to this question! Upvote people! :) – Augustin Riedinger Jul 11 '13 at 14:30
  • Now if only this didn't break the content spoof workaround https://github.com/thoughtbot/paperclip/issues/1429#issuecomment-44291712 – Abram Sep 24 '14 at 00:53
  • 1
    This works pretty good by the end of April, 2017. Just make sure that you restart your application after you do any changes to the files inside your 'initializers' directory ;) – scaryguy Apr 26 '17 at 19:50
27

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
vishnu
  • 869
  • 1
  • 16
  • 25
  • Thank you but I know that this 4 different size of profile pictures. My question is that I receive square version from data facebook, and I want use in my rails app also other 3 versions. Thank you! – hyperrjas May 10 '12 at 11:55
  • 1
    this tells you the sizes, but does not really solve the problem – Tom Prats Aug 29 '13 at 21:01
  • change the url to reflect the different size. you already have the photo id so you have everything you need – light24bulbs May 04 '14 at 23:08
4

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
Justin
  • 535
  • 6
  • 18
2

Instead of changing the config file i just added + "?type=large" to the url.

<%= image_tag current_user.image + "?type=large" %>

so you can request different sizes of it at any time.

<%= image_tag current_user.image + "?type=normal" %>

<%= image_tag current_user.image + "?type=small" %>

Allan
  • 336
  • 3
  • 18