php createimage不会将图像输出到浏览器

php createimage不会将图像输出到浏览器,php,Php,你能帮忙吗 <?php // Create a 200 x 200 image $canvas = imagecreatetruecolor(200, 200); // Allocate colors $pink = imagecolorallocate($canvas, 255, 105, 180); $white = imagecolorallocate($canvas, 255, 255, 255); $green = imagecolorallocate($canvas, 13

你能帮忙吗

<?php

// Create a 200 x 200 image
$canvas = imagecreatetruecolor(200, 200);

// Allocate colors
$pink = imagecolorallocate($canvas, 255, 105, 180);
$white = imagecolorallocate($canvas, 255, 255, 255);
$green = imagecolorallocate($canvas, 132, 135, 28);

// Draw three rectangles each with its own color
imagerectangle($canvas, 50, 50, 150, 150, $pink);
imagerectangle($canvas, 45, 60, 120, 100, $white);
imagerectangle($canvas, 100, 120, 75, 160, $green);

// Output and free from memory
header('Content-Type: image/jpeg');

imagejpeg($canvas);
imagedestroy($canvas);

?>
使用XAMPP,我得到了localhost/drawrectangle.php,其中包含以下不呈现图像的代码,我得到的是一个图像占位符,您能提供帮助吗

<?php

// Create a 200 x 200 image
$canvas = imagecreatetruecolor(200, 200);

// Allocate colors
$pink = imagecolorallocate($canvas, 255, 105, 180);
$white = imagecolorallocate($canvas, 255, 255, 255);
$green = imagecolorallocate($canvas, 132, 135, 28);

// Draw three rectangles each with its own color
imagerectangle($canvas, 50, 50, 150, 150, $pink);
imagerectangle($canvas, 45, 60, 120, 100, $white);
imagerectangle($canvas, 100, 120, 75, 160, $green);

// Output and free from memory
header('Content-Type: image/jpeg');

imagejpeg($canvas);
imagedestroy($canvas);

?>


你到底得到了什么?右键单击占位符“保存图像”,然后将文件加载到文本/十六进制编辑器中,查看其中的内容。如果有任何php错误/警告被输出,它们将嵌入到图像数据的开头,并导致图像数据被视为已损坏。@KristerAndersson如果header()之前有任何输出,php将抛出错误。您应该在此处检查并输出它。请参阅“注意:JPEG支持仅在PHP是根据GD-1.8或更高版本编译的情况下可用。”也许您没有启用GD库(PHP扩展)?