2012-09-10 51 views
2

我正在創建一個將用戶個人資料圖片與我的自定義圖片合併的應用程序。用imagecopymerge很容易做到這一點,但當我正在做fot facebook用戶的個人資料圖片。它不工作我使用這個代碼:將Facebook用戶個人資料圖片與另一張圖片合併

$uid = $facebook->getUser(); 
$userpic = imagecreatefromjpg("http://graph.facebook.com/".$user_id."/picture?type=normal"); 
$mainphoto = imagecreatefromjpeg("img/back.jpg"); 
imagecopymerge($mainphoto, $userpic, 10, 10, -2, -2, 55, 55, 100); 
imagejpeg($mainphoto, "new.jpg", 100); 
imagedestroy($mainphoto); 

它顯示了一個錯誤

致命錯誤:調用未定義功能imagecreatefromjpg()在/home/a7193625/public_html/fb/index.php上第6行

這意味着它沒有得到用戶的圖像,所以我該怎麼辦?如何在我的服務器上下載圖片或在不下載的情況下使用它。

感謝

回答

0

我認爲這個問題是與你的函數名,應該不是imagecreatefromjpeg imagecreatefromjpg

+0

哦對不起它imagecreatefromjpeg但它不工作:( –

+0

你能發佈新的錯誤 –

+0

警告:imagecreatefromjpeg()[function.imagecreatefromjpeg]:無法讀取/home/a7193625/public_html/fb/index.php圖像數據在線6 警告:imagecopymerge():提供的參數不是有效的圖像資源在/home/a7193625/public_html/fb/index.php第8行 –

1

您需要的URL圖像,同時採用

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

只是重定向到圖片地址輸出圖像。這是造成問題的原因。

你只需要一個URL到用戶圖像。

$user_id = $facebook->getUser(); 
$result = file_get_contents("https://graph.facebook.com/{$user_id}?fields=picture.type(normal)"); 
$result = json_decode($result); 
$userpic = imagecreatefromjpeg($result->picture); 

使用這種方式,你將得到圖像的URL,你可以使用你的功能來操縱圖像。

+0

顯示錯誤: 警告:imagecreatefromjpeg()[function.imagecreatefromjpeg]:文件名不能在/ home/a7193625/public_html/fb/index.php在線8 –

+0

確保你獲得Facebook用戶的'userid'。 – Abhishek

+0

是的我正在通過正確的方式獲取用戶的ID,但它沒有捕捉到正確的URL不知道爲什麼:( –

相關問題