facebook图像与另一个图像合并

时间:2012-11-25 16:51:14

标签: image facebook-graph-api merge

facebook image merge

您好,我想开发一个Facebook应用程序。它将进行测验,然后合并证书图像中的个人资料图片。结果。

index.php文件如下

<?php
include_once "fbmain.php";
//if user is logged in and session is valid.
if ($user){
//fql query example using legacy method call and passing parameter
try{
$fql = "select name, hometown_location, sex, pic_square from user where uid=" . $user;
//http://developers.facebook.com/docs/reference/fql/
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
}
catch(Exception $o){
d($o);
}
}
//set page to include default is home.php
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : "home.php";
include_once "template.php";
?>

和home.php如下

<?php
echo '<div id="namaz_content">';
echo '</div>';
echo $userInfo['picture'];
//Get the current users id
$uid = $facebook->getUser();
//create the url
$profile_pic = "http://graph.facebook.com/".$uid."/picture?width=80&height=80";
//echo the image out
echo "<img src=\"" . $profile_pic . "\" />";
echo '<img src="image.php?name=My name is Tushar&result=A%2D&taka=1000&subject=math" />';
?>

和image.php文件如下

<?php
$text=$_GET['name'];
$result=$_GET['result'];
$subject=$_GET['subject'];
$taka='Tk. '.$_GET['taka'].'/-';
$dest = imagecreatefromjpeg('certificate.jpg');
$src = imagecreatefromjpeg('7e142c8d.jpg');
// Allocate A Color For The Text
$red = imagecolorallocate($dest,255,0,0);
$blue= imagecolorallocate($dest,0,0,255);
// Set Path to Font File
$font_path = 'bdquiz.ttf';
// Set Text to Be Printed On Image
// Print Text On Image
imagettftext($dest, 20, 0, 192, 240, $red, $font_path, $text);
imagettftext($dest,35, 0, 72, 380, $red, 'arial.ttf', $result);
imagettftext($dest,15, 0, 318, 420, $red, 'arial.ttf', $taka);
imagettftext($dest,15, 0, 270, 348, $blue, 'arial.ttf', $subject);
imagecopymerge($dest, $src, 468, 186, 0, 0, 80, 80, 100); //have to play with these numbers for it to work for you, etc.
//header('Content-Type: image/png');
imagejpeg($dest);
imagedestroy($dest);
imagedestroy($src);
?>

这很好用。但我希望在image.php用户个人资料图片将代替'7e142c8d.jpg' 解决办法是什么 ?请帮忙

1 个答案:

答案 0 :(得分:0)

我不确定你的编码有多好,所以我会逐步解释它。

在home.php

在顶部添加:

session_start();

并在profile_pic

之后的下一行添加此内容

$_SESSION['profilepic']=$profile_pic;

现在在image.php中,将其添加到顶部

session_start();

更改此

$src = imagecreatefromjpeg('7e142c8d.jpg');

$src = imagecreatefromjpeg('$_SESSION['profilepic']');

或者,如果您不想了解如何操作,并且只是希望工作正常,请复制粘贴。 (我希望你能学习而不是复制粘贴。)

<强> home.php

<?php
session_start();
echo '<div id="namaz_content">';
echo '</div>';
echo $userInfo['picture'];
//Get the current users id
$uid = $facebook->getUser();
//create the url
$profile_pic = "http://graph.facebook.com/".$uid."/picture?width=80&height=80";
$_SESSION['profilepic'] = $profile_pic;
//echo the image out
echo "<img src=\"" . $profile_pic . "\" />";
echo '<img src="image.php?name=My name is Tushar&result=A%2D&taka=1000&subject=math" />';
?>

<强> Image.php

<?php
session_start();
$text=$_GET['name'];
$result=$_GET['result'];
$subject=$_GET['subject'];
$taka='Tk. '.$_GET['taka'].'/-';
$dest = imagecreatefromjpeg('certificate.jpg');
$src = imagecreatefromjpeg('$_SESSION['profilepic']');
// Allocate A Color For The Text
$red = imagecolorallocate($dest,255,0,0);
$blue= imagecolorallocate($dest,0,0,255);
// Set Path to Font File
$font_path = 'bdquiz.ttf';
// Set Text to Be Printed On Image
// Print Text On Image
imagettftext($dest, 20, 0, 192, 240, $red, $font_path, $text);
imagettftext($dest,35, 0, 72, 380, $red, 'arial.ttf', $result);
imagettftext($dest,15, 0, 318, 420, $red, 'arial.ttf', $taka);
imagettftext($dest,15, 0, 270, 348, $blue, 'arial.ttf', $subject);
imagecopymerge($dest, $src, 468, 186, 0, 0, 80, 80, 100); //have to play with these numbers for it to work for you, etc.
//header('Content-Type: image/png');
imagejpeg($dest);
imagedestroy($dest);
imagedestroy($src);
?>