您好我正在尝试获取用户个人资料照片,然后根据我的Facebook应用程序要求合并到现有图像中。但我很难检索并将图片分配给'imagecreatefromjpeg()'函数。
我需要帮助,如何做到这一点。如果需要先保存图片然后合并,那么如何将图片从fb图形链接保存到磁盘?请帮助。
$userPicture = file_get_contents('http://graph.facebook.com/' . $userId) -> picture;
$url = 'http://graph.facebook.com/' . $userId -> picture;
file_put_contents($img, file_get_contents($url));
$src = imagecreatefromjpeg($userPicture);
//$src = imagecreatefromjpeg("https://graph.facebook.com/" . $userId . "/picture?type=large");
$dest = imagecreatefromjpeg('image.jpg');
imagecopymerge($dest, $src, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct);
imagejpeg($dest, 'fImage.jpg');
imagedestroy($dest);
imagedestroy($src);
答案 0 :(得分:2)
你混合了很多东西,应该很简单:
$url = "http://graph.facebook.com/{$userId}/picture";
// You may download the image first
$img = 'my_facebook_image.jpg';
file_put_contents($img, file_get_contents($url));
// And work with downloaded one
$src = imagecreatefromjpeg($img);
// Or you may use it directly if the fopen wrappers have been enabled
$src = imagecreatefromjpeg($url);
// Do whatever you want with an image resource...