Search code examples
phpfacebookgdphp-gd

PHP-GD How I can check the type (jpeg, gif ..) with a url of facebook?


If a user has no photo facebook instead of a jpeg get a gif. How I can check the type?

I have tried the following:

$PIC_Friend = imagecreatefromstring(file_get_contents('http://graph.facebook.com/'. id .'/picture?width=50&height=50')); 
if(imagejpeg($PIC_Friend)) { 
..
} elseif (imagegif($PIC_Friend)) { 
...

This works but replaces all my template (the remaining elements of php) and only shows photo of accused imagejpg method imagegif etc. ..


Solution

  • Ok.

    The solution is simple .. just use the php method exif_imagetype.

    http://php.net/manual/en/function.exif-imagetype.php