1

I want to use the Facebook users Profile Picture in my Application.

I think I should use the following function, but I'm not sure if that's correct:

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

My goal is to place the profile picture on top of another image.

I think I have to use something like this:

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

To conclude... I want to use the profile picture of a user an add it on another picture, how can I do this ?

ThdK
  • 9,916
  • 23
  • 74
  • 101
Salexes
  • 11
  • 1

2 Answers2

1

grab user profile pic using following code:

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

Now place in in your main photo:

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

Now $mainphoto will contain the main photo and userpic on it. you have to follow the same for all userpics you want to put on the mainphoto.

finally download the photo in server and free the memory:

imagejpeg($mainphoto, "save_as_this_name.jpg", 100);
imagedestroy($mainphoto);
sha256
  • 3,029
  • 1
  • 27
  • 32
  • Thanks for the detailed answer. Do you mean I have to do it this way? public function getImg() { $userpic = imagecreatefromjpeg("http://graph.facebook.com/".$user_id."/picture?type=normal"); } – Salexes Mar 30 '12 at 15:40
  • This is how the begining of my"picgenerator.php" looks like foreach ((array)$_CONFIG['texte'] as $key=>$val) { $ttfsize = $val['fontNameSize']; $ttf = $val['fontNamePfad']; $t_x = $val['X']; $t_y = $val['Y']; if ($val['BILD']) { $source = @ImageCreateFromPNG ($hippibild); list($width, $height)= getimagesize($hippibild); ImageCopy ( $picture , $source, $t_x, $t_y , 0 , 0 , $width , $height ); – Salexes Mar 30 '12 at 15:51
  • $source = @ImageCreateFromPNG (getImg()); list($width, $height)= getimagesize(getImg()); ImageCopy ( $picture , $source, 430, 80 , 0 , 0 , $width , $height ); } else { $text = $val['TEXT']; $text = str_replace('%birthday%', $birthday, $text); New prob.not sure where your code. Please help :) – Salexes Mar 30 '12 at 15:51
  • New problem I am not sure where to use your suggestet code. It would be nice if you could help me here, too. – Salexes Mar 30 '12 at 16:16
  • you cannot directly upload an image that is created by php. you have to download the photo in your server first. and then upload it in the way, you normally upload photo using graph api. And here i just said how to create the photo using php and download it in your server. – sha256 Mar 30 '12 at 16:50
  • Ahh okay, thank you, in the picgenerator do an additional thing it writes text on the picture. So i have to use the downloaded picture, right. ? :) – Salexes Mar 30 '12 at 17:08
  • you can do all operations (puting profile pic on the main photo, adding text etc etc...) on the photo & then download it. Downloading then adding text and then downloading again is a bad idea, I guess. You can use `imagestring` function for adding text. e.g. `$color = imagecolorallocate($mainpic, 100, 20, 200);` `imagestring($mainpic, 50, 127, 242, "Your Text", $color);` :) – sha256 Mar 30 '12 at 17:29
  • Thank you for this quick answer, but sadly I can not get it woriking. Is it possible that you help me in this thing (via Skype/Teamviewer(?)) – Salexes Mar 30 '12 at 22:57
  • It would be really nice, i tried to get it the whole day but it didn't work :/ – Salexes Mar 31 '12 at 23:19
  • Hmm Is here anyone who can help me, i think I nearly got it but i cant find the mistake, i have done :/ – Salexes Apr 01 '12 at 12:48
0

I do not know php but i think this example from here may help you:

    <?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);
?>
ThdK
  • 9,916
  • 23
  • 74
  • 101