I'm trying to biuld an eapplication for Facebook where I merge the users profile image with a background image and the name of the user. This image is a reward for those who succesfully answer a quiz.
This is the relavant code from the page where the user is direceted after submitting there answers:
if ( $totalCorrect == 10) {
echo "Congrats!";
echo "<div id='results'>$totalCorrect / 10 correct</div>";
echo '<img src="image.php">';
?>
And this is the code in 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);
?>
If I exchange the $url to a static image the code works, but not whene i try to fetch the profile of the user. Any suggestions? Thank's in adwance!
create new php file name a.php and store following
$headers = get_headers('https://graph.facebook.com/".$user[id]."/picture',1);
$url = $headers['Location'];
on the original file, call the a.php file like below:
require_once 'a.php';
$dst = imagecreatefromjpeg($url);
imagecopymerge($im, $dest, 10, 10, 0, 0, 180, 180, 100);
hope it helps!