2

I want to fetch facebook profile picture programmatically and then load it as texture in our engine. Since our engine supports only several picture formats (bmp, tga, png) I want to fetch picture from facebook in png format.

Now I see that there are two formats of profile pictures, gif for those who have not uploaded picture and jpg for those who have.

Thanks in advance.

Dmitrii Tokarev
  • 137
  • 3
  • 9

3 Answers3

6

You have your answer there - Facebook only returns GIF or JPG images via the API - you'll need to convert them in your own code if you can't store JPG

Igy
  • 43,710
  • 8
  • 89
  • 115
  • I was asking this question because thought that there can be some parameters in the API that can allow me to choose format of the image, for example there are width and height parameters that work with gif images (because this kind of images are facebook default images) but they are not described in Pictures section in http://developers.facebook.com/docs/reference/api. Going to add suppot of jpg format to our engine. – Dmitrii Tokarev Jul 05 '12 at 11:36
2

Facebook indeed returns profile pictures as JPGs. However, you can use image manipulation solutions for dynamically converting to different formats. For example, you can do that using Cloudinary - http://cloudinary.com (disclaimer - I work at Cloudinary).

With Cloudinary you can fetch Facebook profile pictures, make any image transformation of your preference, and convert to any format of all major images filetypes (including PNG). The transformation is easily made, on-the-fly, and delivered through a fast CDN. The images will even be refreshed after a user changes his/her profile photo

Here's an example of a Facebook profile image. Here's the original:

https://graph.facebook.com/billclinton/picture?type=large

Here's the same image, fetched from facebook in real-time, resized to a 80px width and 120px height, with fill cropping, and converting it to a PNG file: https://res.cloudinary.com/demo/image/facebook/w_80,h_120,c_fill/billclinton.png

You'll need replace "demo" with your own account's cloud name

Community
  • 1
  • 1
Itay Taragano
  • 1,901
  • 1
  • 11
  • 12
1

Facebook only returns images in jpeg format. If your engine only supports bmp, tga, and png the best thing to do is to convert the jpg to png programmatically once you request it.

Access the image using the graph api:

  1. https://graph.facebook.com/nike/picture?type=large (The Nike facebook page image)
  2. Convert the image to a png using imagecreatefromjpeg (for php) or an equivalent

The reply below has more details.

Convert jpg image to gif, png & bmp format using PHP

Community
  • 1
  • 1
Neil
  • 1,066
  • 6
  • 10