【问题标题】:Facebook Application - User Picture?Facebook 应用程序 - 用户图片?
【发布时间】:2012-03-30 11:28:10
【问题描述】:

我想在我的应用程序中使用 Facebook 用户的个人资料图片。

我认为我应该使用以下函数,但我不确定这是否正确:

     public function getImg() { 
        $img = file_get_contents('https://graph.facebook.com/'.getUser().'/picture?type=normal'); 
        return $this->img;
     } 

我的目标是将个人资料图片放在另一张图片之上。

我想我必须使用这样的东西:

ImageCopy ( $picture , $source, 445, 160 , 0 , 0 , $width , $height );

总结...我想使用用户的个人资料图片并将其添加到另一张图片上,我该怎么做?

【问题讨论】:

  • 您是否尝试过此处显示的代码?如果是,出了什么问题?
  • 好吧,我试过了,可惜没用。个人资料图片未添加到另一张图片上。
  • 你确定你是从 facebook 获得的真实图片吗?

标签: facebook facebook-graph-api user-profile


【解决方案1】:

使用以下代码获取用户个人资料图片:

$userpic = imagecreatefromjpeg("http://graph.facebook.com/".$user_id."/picture?type=normal");

现在放入您的主照片中:

$mainphoto = imagecreatefromjpeg("path/to/main/photo.jpg");
imagecopymerge($mainpic, $userpic, $x, $y, -2, -2, 55, 55, 100);

现在$mainphoto 将包含主照片和用户图片。 对于要放在主照片上的所有用户图片,您必须遵循相同的操作。

最后在服务器中下载照片并释放内存:

imagejpeg($mainphoto, "save_as_this_name.jpg", 100);
imagedestroy($mainphoto);

【讨论】:

  • 感谢您的详细解答。你的意思是我必须这样做吗?公共函数 getImg() { $userpic = imagecreatefromjpeg("graph.facebook.com/".$user_id."/…); }
  • 这就是我的“picgenerator.php”开头的样子 foreach ((array)$_CONFIG['texte'] as $key=>$val) { $ttfsize = $val['字体名称大小']; $ttf = $val['fontNamePfad']; $t_x = $val['X']; $t_y = $val['Y']; if ($val['BILD']) { $source = @ImageCreateFromPNG ($hippibild);列表($宽度,$高度)= getimagesize($hippibild); ImageCopy ( $picture , $source, $t_x, $t_y , 0 , 0 , $width , $height );
  • $source = @ImageCreateFromPNG (getImg());列表($宽度,$高度)= getimagesize(getImg()); ImageCopy ( $picture , $source, 430, 80 , 0 , 0 , $width , $height ); } 其他 { $text = $val['TEXT']; $text = str_replace('%birthday%', $birthday, $text);新问题。不确定您的代码在哪里。请帮忙:)
  • 新问题我不确定在哪里使用您的建议代码。如果你也能在这里帮助我,那就太好了。
  • 不能直接上传php创建的图片。您必须先在服务器中下载照片。然后以这种方式上传,您通常使用graph api上传照片。在这里我只是说如何使用 php 创建照片并将其下载到您的服务器中。
【解决方案2】:

我不懂php,但我认为here 的这个例子可能对你有帮助:

    <?php
// Create image instances
$src = imagecreatefromgif('php.gif');
$dest = imagecreatetruecolor(80, 40);

// Copy
imagecopy($dest, $src, 0, 0, 20, 13, 80, 40);

// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);

imagedestroy($dest);
imagedestroy($src);
?>

【讨论】:

    猜你喜欢
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多