2012-11-25 47 views
1

facebook图像合并facebook图像与另一图像合并

嗨我想开发一个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' 什么是解决方案? PLZ帮助

回答

0

我不知道你在编码上有多好,所以我正在逐步解释它。

在home.php

在顶部添加此:

session_start();

,并在下一行后image.php profile_pic

$_SESSION['profilepic']=$profile_pic;

现在添加此,顶部添加

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

感谢,但它不工作。问题在$ line_pic =“http://graph.facebook.com/".$uid."/picture?width=80&height=80”;当该行在标签下时,则可正常工作。但抓住形象不好。导致此链接不是真正的图片网址。如果我在地址栏中使用这个lin,链接将重定向到http://profile.ak.fbcdn.net/hprofile-ak-ash3/c15.8.100.100/s80x80/600419_10209216737360_3237_s.jpg –