如何将Facebook用户显示的图片保存到磁盘上或不保存就使用它? [英] How save Facebook user display picture to the disk or use it without saving?

查看:241
本文介绍了如何将Facebook用户显示的图片保存到磁盘上或不保存就使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试获取用户个人资料图片,然后按照我的Facebook应用程序要求合并到现有图像中.但是我在检索图片并将图片分配给"imagecreatefromjpeg()"函数时遇到了困难.

Hello I am trying to get the user profile picture and then merge into an existing image as per my Facebook app requirement. But I am having difficulty in retrieving and assigning the picture to ‘imagecreatefromjpeg()’ function.

我需要有关此的帮助,如何实现此目的.如果需要先保存图片然后合并,那么如何将图片从fb图形链接保存到磁盘?请帮助.

I need help regarding this, how do achieve this. If it’s necessary to save the picture first and then merge, then how can I save the pic from the fb graph link to disk? Kindly help.

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

推荐答案

您混合了太多东西,应该非常简单:

You mixing too many things up, it should be really simple:

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

这篇关于如何将Facebook用户显示的图片保存到磁盘上或不保存就使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆