函数imagejpeg($image)不显示图像


function imagejpeg($image) doesn't display the image

我正在尝试使图像生成器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中显示错误'The image "…" cannot be display because it contains errors'。但是当我输入imagejpeg($image,"new.jpg");而不是imagejpeg($image);它使img文件正确。有人知道我应该怎么做来解决这个问题吗?

我把你的代码放在我的本地web服务器上,拿出header调用,我得到了一个错误,说函数imagefontheight是未定义的。

我想你可能没有安装GD库,所以调用任何image...函数失败。

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