1

I'm using cURL to get an image from the Facebook SDK, but the image provided is in JFIF format. I tried to use some functions to convert it, as imagejpeg() and imagepng(), but my host don't support these. I also tried to decode the file as described here, but no success either. Any help or suggestions will be appreciated.

//Image handler
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_URL, $jsonresponse['url']);
$data = curl_exec($ch);
curl_close($ch);

$dataDecoded = base64_decode($data); //Last try with base64 decoder
$fb_image = 'fb_picture.jpg';
file_put_contents($fb_image, $dataDecoded); 

I got no errors, but the saved image (fb_picture.jpg) isn't readable and have 0KB.

leonardofmed
  • 842
  • 3
  • 13
  • 47

1 Answers1

0

JFIF is already JPEG with aditional metadata about the person in the photo. See https://www.rfc-editor.org/rfc/rfc2798#page-5 for more info. JFIF is used specifically for pictures of persons. Your host needs imagejpeg() and bundle to work with jpeg. Install it as a PHP module.

Community
  • 1
  • 1
jg6
  • 318
  • 2
  • 12
  • Thanks for the info! The problem is that the host is a shared host, so I can't install anything on it. It's possible to get the data from FB directly as a JPEG? Or use some other way to "convert" it? – leonardofmed Apr 08 '19 at 19:33
  • Well you can try parsing raw HTML returned by FB, but there may be other options. – jg6 Apr 08 '19 at 19:38
  • Actually, from this FB request I get only the URL. The HTML page that opens is a empty one and the picture come as a automatic download. – leonardofmed Apr 08 '19 at 19:50
  • I meant try to parse profile page. fb.me/userid as far as I know. It includes profile pic. – jg6 Apr 09 '19 at 07:01