我正在尝试为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交换为静态图像,则代码可以正常工作,但是当我尝试获取用户的配置文件时却不行。有什么建议?谢谢你的推荐!
答案 0 :(得分:2)
创建新的php文件名a.php并存储以下
$headers = get_headers('https://graph.facebook.com/".$user[id]."/picture',1);
$url = $headers['Location'];
在原始文件上,调用如下的a.php文件:
require_once 'a.php';
$dst = imagecreatefromjpeg($url);
imagecopymerge($im, $dest, 10, 10, 0, 0, 180, 180, 100);
希望它有所帮助!