2012-03-09 19 views
0

私はFacebookのためのアプリケーションを配布しようとしています。ここでは、ユーザープロファイルのイメージを背景イメージとユーザーの名前でマージします。この画像は、クイズに成功した人の報酬です。merge facebook profile with text and image

これは、ユーザーがそこに答えを提出した後direcetedされているページからrelavantコードです:

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

のコードですコードは動作しますが、ユーザーのプロファイルを取得しようとしたときには表示されません。助言がありますか?ありがとうございました!

答えて

2

以下のようにa.phpファイルを呼び出し、元のファイルに

$headers = get_headers('https://graph.facebook.com/".$user[id]."/picture',1); 
$url = $headers['Location']; 

次の新しいPHPファイル名a.phpとストアを作成:

require_once 'a.php'; 

$dst = imagecreatefromjpeg($url); 
imagecopymerge($im, $dest, 10, 10, 0, 0, 180, 180, 100); 

はそれが役に立てば幸い!