【问题标题】:How save Facebook user display picture to the disk or use it without saving?如何将 Facebook 用户显示图片保存到磁盘或在不保存的情况下使用它?
【发布时间】:2012-03-18 08:36:01
【问题描述】:

您好,我正在尝试获取用户个人资料图片,然后根据我的 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);

【问题讨论】:

    标签: php facebook facebook-graph-api


    【解决方案1】:

    你混的太多了,应该很简单:

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

    【讨论】:

    • 谢谢。但是,当我试图直接访问它时,它给了我这个警告。 Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'http://graph.facebook.com/100003482890169/picture' is not a valid JPEG file 保存文件时如何将其保存为 .jpg 文件?
    • 这是因为该用户没有图像,并且用户的默认占位符图像是 GIF 而不是 JPEG。在处理之前下载图像并检查它的 mime 可能是个好主意...
    猜你喜欢
    • 1970-01-01
    • 2022-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-18
    • 1970-01-01
    • 2012-01-17
    • 1970-01-01
    相关资源
    最近更新 更多