Php GD 无法进行简单测试

Php GD not working for a simple test

Php GD 有时有效有时无效!

我正在使用一个简单的测试,但仍然收到错误消息。

test.php 中的代码:

<?php
header('Content-type: image/png');
$x = 50; 
$y = 100; 
$image = imagecreatetruecolor($x,$y);
imagepng($image);
imagedestroy($image); 
?>

gd 中的代码test.php:

<html>
<body>
<img src="test.php">
</body>
</html>

GD 支持已启用,我使用捆绑的 GD 版本(2.1.0 兼容)

你能帮忙吗?

做一件事,检查您的 gd 库是否已安装:

if (extension_loaded('gd') && function_exists('gd_info')) {
    echo "PHP GD library is installed on your web server";
}
else {
    echo "PHP GD library is NOT installed on your web server";
}

并确保 <?php 之前没有任何内容,并从您的 test.php 文件中删除末尾的 ?>