我正在尝试为Facebook创建一个应用程序,将用户的个人资料图像与背景图像和用户名称合并。这张图片是对那些成功回答测验的人的奖励。
这是用户提交答案后收到的页面上的相关代码:
if ( $totalCorrect == 10) {
echo "Congrats!";
echo "<div id='results'>$totalCorrect / 10 correct</div>";
echo '<img src="image.php">';
?>
这是image.php 中的代码
<?php
// Create image instances
$im = imagecreatefromjpeg('xxx.jpg');
$black = ImageColorAllocate($im, 0, 0, 0);
//The canvas's (0,0) position is the upper left corner
//So this is how far down and to the right the text should start
$start_x = 200;
$start_y = 20;
$font = 'arial.ttf';
Imagettftext($im, 12, 0, $start_x, $start_y, $black, $font, 'text to write');
$url = "http://graph.facebook.com/".$user_profile. "/picture";
$dest = imagecreatefromjpeg($url);
// Copy and merge
imagecopymerge($im, $dest, 10, 10, 0, 0, 180, 180, 100);
//Creates the jpeg image and sends it to the browser
//100 is the jpeg quality percentage
// Output and free from memory
header('Content-Type: image/jpg');
imagejpeg($im);
imagedestroy($dest);
imagedestroy($src);
?>
如果我把$url换成一个静态图像,代码就可以工作,但当我试图获取用户的配置文件时就不行了。有什么建议吗?谢谢你!
创建新的php文件名a.php并存储以下
$headers = get_headers('https://graph.facebook.com/".$user[id]."/picture',1);
$url = $headers['Location'];
在原始文件上,调用php文件,如下所示:
require_once 'a.php';
$dst = imagecreatefromjpeg($url);
imagecopymerge($im, $dest, 10, 10, 0, 0, 180, 180, 100);
希望它能有所帮助!