Php 函数imagejpeg($image)不';不要显示图像

Php 函数imagejpeg($image)不';不要显示图像,php,Php,我正在尝试制作图像生成器php文件,我使用以下代码> <?php header('content-type: image/jpeg'); $email = 'example@example.com'; $email_length = strlen($email); $font_size = 4; $image_height = imagefontheight($font_size); $image_width = imagefontheight($font_size) * $email_l

我正在尝试制作图像生成器php文件,我使用以下代码>

<?php
header('content-type: image/jpeg');
$email = 'example@example.com';
$email_length = strlen($email);
$font_size = 4;
$image_height = imagefontheight($font_size);
$image_width = imagefontheight($font_size) * $email_length;
$image = imagecreate($image_width, $image_height);
imagecolorallocate($image, 255, 255, 255);
$font_color = imagecolorallocate($image, 0, 0, 0);
imagestring($image, $font_size, 0, 0, $email, $font_color);
imagejpeg($image);
?>


当我在Chrome中加载文件时,它没有显示任何图像。在Mozilla中显示错误“图像”…“无法显示,因为它包含错误”。但是当我把imagejpeg($image,“new.jpg”);而不是图像JPEG($image);它使img文件正确。有人知道我应该怎么做才能解决这个问题吗?

我将您的代码放在本地web服务器上,执行了
header
调用,但我收到一个错误,说函数
imagefontheight
未定义

我想您可能没有安装GD库,因此调用任何
image…
函数都会失败


我不能再告诉你了,除非你告诉我们你有什么操作系统,以及PHP是如何运行的。(CLI,在Apache中,等等)

显示的可能是PHP解析错误,因为您已将内容类型设置为图像。我已经在本地运行了这个程序,它似乎运行得很好,我建议您注释掉
header
调用,然后直接运行脚本,看看是否有任何PHP错误出现。我尝试过,结果显示没有错误,但浏览器中有原始数据。我已经安装了GD,已经检查过了。我使用Windows 7 x86,在NetBeans中编写PHP,并使用Apache与XAMPP控制面板一起运行。可能会有额外的数据发送到浏览器删除结束的PHP脚本标记,并确保开始脚本标记前没有空格。