我正在使用此代码将文本与图像合并,并且工作正常。但是当我将此代码与 Facebook 应用程序一起使用时,它不会显示任何输出。谁能帮我解决问题?据我所知,问题出在这一行:
header("Content-Type: image/jpeg");
当我删除它时,它会显示一些混乱的输出。
<?php
header("Content-Type: image/jpeg");
$im = ImageCreateFrompng("jump_empty.png");
$black = ImageColorAllocate($im, 255, 255, 255);
$start_x = 10;
$start_y = 20;
Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'ambient.ttf', "hellooo");
Imagejpeg($im, '', 100);
ImageDestroy($im);
?>
这是我用于 Facebook 应用程序的代码:
<?php
include_once 'facebook.php';
include_once 'config.php';
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET_KEY,
'cookie' => true,
'domain' => '_____'
));
header("Content-Type: image/jpeg");
$session = $facebook->getSession();
if (!$session) {
$url = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'read_stream,publish_stream'
));
echo "<script type='text/javascript'>top.location.href = '$url';</script>";
} else {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
echo "Hey " . $me['name'] . "!<br />";
$im = ImageCreateFrompng("jump_empty.png");
$black = ImageColorAllocate($im, 255, 255, 255);
$start_x = 10;
$start_y = 20;
Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'ambient.ttf', 'hello');
Imagejpeg($im, '', 100);
ImageDestroy($im);
}
catch (FacebookApiException $e) {
echo "Error:" . print_r($e, true);
}
}
?>