当我在页面中调用我的图像调整大小功能时,它运行平稳并调整我的图像大小但是当我将它包含在我的索引页面并从index.php调用它时,标题不会发送,它会生成一个像这样的长文本< / p>
=>GIF87aªç–ƒx‡dWtaZffeCA<ÕƶCBBŠVNfXT;BC§‡w²¤™wxw¹†g‡˜–êÆ©C;:x‡‡ˆˆ…
等等。请解决我的问题,否则我将直接在index.php中创建此函数?
这是我的function.php页面代码
class img{
function resize()
{
// File and new size
$filename = 'upload/845.gif';
$percent = 0.5;
// Content type
ob_start();
echo header("Content-Type: image/gif");
ob_end_clean();
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromgif($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
@imagegif($thumb);
imagedestroy($thumb);
}
}
这是我下面的index.php代码
<html>
<body>
<?php
include("function.php");
$img_resize=new img;
$img_resize->resize();
?>
</body>
</html>
答案 0 :(得分:2)
您在输入body
标记后发送标题信息。
如果您要显示的只是一张图片,我建议您完全删除HTML。
答案 1 :(得分:2)
您需要创建一个单独的文件来输出图像,然后将其加载到<img>
标记中。
// image.php
include("function.php");
$img_resize=new img;
$img_resize->resize();
// HTML file
<html>
<body>
<img src="image.php" />
</body>
</html>
如果您尝试将图像包含在HTML文件中,那就是这样。如果您只是尝试输出图像,正如其他人所暗示的那样,那么您根本不需要任何HTML来输出图像。
答案 2 :(得分:-1)
ob_start();
echo header("Content-Type: image/gif");
ob_end_clean();
尝试就像这样
header("Content-Type: image/gif");