Site icon Web Niraj

Facebook API: Generating a Large Square Profile Image

With the introduction of Timeline users have larger profile images, but Facebook still restrict the “square” image to 50px by 50px. Here is a clever way of generating a new thumbnail image for the user (on the fly) using the Facebook Graph API and the PHP GD2 library (image manipulation).

The below code gets the image for a given ID from Facebook, and crops the image to what Facebook uses on the Timeline profile. The result is a square image in various dimensions. Some users will have a large square image (155px), while others might have a smaller one (75px).

See the gist on github.

You can call this script by pasting the code into a file (e.g. crop.php) and then navigating to: crop.php?id=60506094. Replace my Facebook ID with whatever you want to see the result.

Exit mobile version