FB Profile Pic always returned as ".jpg"?
Trying to pull user images via the Facebook Social Graph.
Finding it odd that no matter what I upload the image as (gif, bmp, tiff, or jpg), my call to https://graph.facebook.com/507988137/picture?type=larg开发者_开发知识库e (my pic) always returns a jpg.
Does anyone know if I'm OK assuming that his image is always a "jpg"? I'm using php get_file_contents to pull the images & would prefer not having to sniff test them for various formats.
Facebook doesn't save the original image that you upload. Instead it converts all uploaded images to jpgs of 4 different sizes to support all the different places where the image may be displayed.
In case you are interested, Facebook basically has this down to a science, in fact, I've read several times that they are the largest image hosting service in the world. More details within this Facebook blog post, Facebook Photos Infrastructure
That's because FaceBook stores it as a jpg, because that is in general the most efficient image format for pictures. It's always a good idea to check if the data is what you expect. Checking image type is quite easy. It will always be a web format, which basically comes down to jpg, png and gif, with gif being very unlikely because of its limitations (GIF can contain 256 colors at most, and is generally larger than png. Has license limitations too). BMP is not a web format and cannot be displayed in most browsers. You will not get a BMP from that url.
make sure you also handle the case where a gif is returned to you. This is the default profile pic for users that doesn't update their profile pic
精彩评论