New and Easy Way to Get Facebook User Profile Pic in Alternate Sizes

It is very common for a Facebook application to display profile picture of the current Facebook user and/or profile pictures of the user’s friends.

In the past, Facebook provides only a few “sizes” for us to choose from, like normal, large etc.  Yet, this may not fit well in the application.  As a result, developers have to either display it by either cropping the images or use CSS/HTML code to show it in the “desired” size.  However, this will create problem as cropping or resizing the images may have adverse impact on presenting the user’s profile pic (e.g. part of the face is cut).

But here is a good news!  This week, Facebook has released updates to their APIs to allow us to retrieve user’s profile pictures in varying sizes.  Alternate profile picture sizes can be queried via the Graph API and FQL.

To retrieve a profile picture in an alternate size via the Graph API, add the optional width and height fields as URL parameters:

This will return a HTTP 302 redirect to a profile picture with a minimum size of 121×100 while trying to preserve the aspect ratio. You can add the URL parameter redirect=false to retrieve just the URL to the pciture. Ifwidth=height then a square picture will always be returned.

You can also query for profile pictures of varying size using FQL:

SELECT url, real_width, real_height FROM profile_pic WHERE id=me() AND width=121 AND height=100

(try this query)

A small enhancement done by Facebook but is really handy!

This entry was posted in Development Tips, news and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *