Facebook SDK返回个人资料图片为JFIF,如何在PHP中转换为JPG / PNG?

问题描述 投票:0回答:1

我正在使用cURL从Facebook SDK获取图像,但提供的图像是JFIF格式。我尝试使用一些函数来转换它,如imagejpeg()imagepng(),但我的主机不支持这些。我也尝试将文件解码为described here,但也没有成功。任何帮助或建议将不胜感激。

//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); 

我没有错误,但保存的图像(fb_picture.jpg)不可读,并且有0KB。

php facebook-php-sdk image-conversion jfif
1个回答
1
投票

JFIF已经是JPEG,其中包含有关照片中人物的附加元数据。有关更多信息,请参阅https://tools.ietf.org/html/rfc2798#page-5。 JFIF专门用于人物照片。您的主机需要imagejpeg()和bundle才能使用jpeg。将其安装为PHP模块。

© www.soinside.com 2019 - 2024. All rights reserved.