1

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. ..

ephramd
  • 561
  • 2
  • 15
  • 41

4 Answers4

1

Ok.

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

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

ephramd
  • 561
  • 2
  • 15
  • 41
0
$img_info = getimagesize($file_path);
if($img_info['mime'] == 'image/pjpeg' || $img_info['mime'] == 'image/jpeg') {
    echo 'It is a .jpeg';
}
Samuil Banti
  • 1,735
  • 1
  • 15
  • 26
0

You can use exif_imagetype

$type = exif_imagetype('path/to/yourImage');

$type can be IMAGETYPE_GIF,IMAGETYPE_JPEG,IMAGETYPE_PNG,.... This method is much faster than getimagesize. It will output false if your file is not an image.

Lewis
  • 14,132
  • 12
  • 66
  • 87
0

You can read headers with get_headers

$headers = get_headers('http://graph.facebook.com/'. id .'/picture?width=50&height=50');

Output

array(22) 
{
  [0]=> string(23) "HTTP/1.1 302 forced.302"
  ...
  [14]=> string(24) "Content-Type: image/jpeg"
  ...
  string(17) "Connection: close"
}
Bora
  • 10,529
  • 5
  • 43
  • 73