我想做的是:
能做到吗?
require_once("src/facebook.php");
$configurar = array();
$configurar['appId'] = '2033xxxxx389';
$configurar['secret'] = 'cc3xxxx9b1';
$configurar['fileUpload'] = true;
$facebook = new Facebook($configurar);
$signed_request = $facebook->getSignedRequest();
$__idPagina = $signed_request["page"]["id"];
$__adminPagina = $signed_request["page"]["admin"];
$__statusLike = $signed_request["page"]["liked"];
$__pais = $signed_request["user"]["country"];
$__locale = $signed_request["user"]["locale"];
$_idUsuario = $facebook->getUser();
?>
<html>
<head></head>
<body>
<?
if($_idUsuario)
{
try
{
if($__statusLike)
{
//AQUI VAI A PARTE QUE FUNCIONA A MÁGICA DA FOTO! POORRA
// DEFINIR VARIAVEIS
$foto_x = $_idUsuario."_x.jpg";
$foto_y = $_idUsuario."_y.jpg";
$img = $_idUsuario.".jpg";
copy('http://graph.facebook.com/'.$_idUsuario.'/picture?width=150&height=150', 'lixeira/'.$foto_x);
//ARMA ALEATÓRIA NA BAGAÇA
$armaRandomica = rand(1,10);
//DEFINE O MOLDE DE ACORDO COMO O NUMERO QUE PEGOU AI /\
switch ($armaRandomica) {
case 1:
$moldeArma = "molde/_bazuka.jpg";
break;
case 2:
$moldeArma = "molde/_espada.jpg";
break;
case 3:
$moldeArma = "molde/_espingarda.jpg";
break;
case 4:
$moldeArma = "molde/_faca.jpg";
break;
case 5:
$moldeArma = "molde/_granada.jpg";
break;
case 6:
$moldeArma = "molde/_metralhadora.jpg";
break;
case 7:
$moldeArma = "molde/_nokia.jpg";
break;
case 8:
$moldeArma = "molde/_pistola.jpg";
break;
case 9:
$moldeArma = "molde/_shotgun.jpg";
break;
case 10:
$moldeArma = "molde/_sniper.jpg";
break;
}
echo '<img src="'.$moldeArma.'" />';
//JUNTAR A FOTO DO PERFIL COM O MOLDE!
header("Content-type:image/jpeg");
$stamp = imagecreatefromjpeg($foto_x);
$im = imagecreatefromjpeg($moldeArma);
$marge_right = 20;
$marge_bottom = 330;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
imagejpeg($im, $foto_y,100);
imagedestroy($im);
exit;
//USA ISSO COMO $perfilUsuario['name'] e talz!
$perfilUsuario = $facebook->api('/me','GET');
//MOSTRA A FOTO PRO NEGRO!
echo '<img src="lixeira/'.$foto_x.'" />';
}
else
{
echo '<center><img src="imagens/curta.png"/></center>';
}
}
catch(FacebookApiException $e)
{
$urlLogin = $facebook->getLoginUrl();
echo 'Porfavor <a href="'.$urlLogin.'">LOGUE!</a>';
error_log($e->getType());
error_log($e->getMessage());
}
}
else
{
$urlLogin = $facebook->getLoginUrl();
echo 'Porfavor <a href="'.$urlLogin.'">LOGUE!</a>';
}
?>
</body>
</html>
这就是我从该代码中得到的,我该怎么做才能解决这个错误?
http://i.stack.imgur.com/lrFKd.png
帮助我的人= D
答案 0 :(得分:0)
您的代码存在两个问题:
在第81行,您正在输出内容类型标题。单个文件只能输出1个内容类型,它可以是HTML文件,也可以是图像文件。稍后详细介绍
在第83行,您正在尝试从Facebook加载图像(imagecreatefromjpeg($ foto_x);),这是无法加载的。您只在此处指定图像的名称(1100000000_x.jpg),没有目录或位置,因此PHP假定是本地文件,并且正在尝试加载与PHP脚本位于同一目录中的文件。我不熟悉Facebook API,但我怀疑应该通过HTTP从服务器下载图像,具体取决于您可能允许或不允许的服务器设置;
$ stamp = imagecreatefromjpeg('http://facebook.com/path/to/image/'。$ foto_x);
回到第一期;无法在单个PHP脚本中同时输出图像和HTML。一种选择可能是从Facebook加载图像,操纵它,将其写入文件并将其用作IMG标记的'src',例如:
imagejpeg($im, $foto_y,100, '/full/path/to/mynewfilename.jpg');
但是,这可能会快速填满您的服务器
另一种选择是将脚本分成两个单独的文件;
1)输出HTML的文件
2)生成图像的文件
此页面将输出HTML并包含指向图像生成.php页面的IMG标记
<!DOCTYPE HTML>
<html>
<head>.....</head>
<body>
<img src='./my_super_image.php' /><!-- <<<< The name of your image script -->
</body>
</html>
此页面将生成并输出图像(仅图像,没有别的)!:
<?php
require_once("src/facebook.php");
.....
header("Content-type:image/jpeg");
$stamp = imagecreatefromjpeg('http://facebook.com/path/to/' . $foto_x);
$im = imagecreatefromjpeg($moldeArma);
$marge_right = 20;
$marge_bottom = 330;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
imagejpeg($im, $foto_y,100);
imagedestroy($im);
?>
上面的代码只是为了说明,没有经过测试!