php图像生成错误无法显示,因为它包含错误

php图像生成错误无法显示,因为它包含错误,php,Php,我试图改变一个透明图像的颜色使用gd库我是新的gd库编译代码,它给出了错误 图像无法显示,因为它包含错误 这是我生成png图像的代码 <?php header("Content-type: image/png"); $source=imagecreatefrompng('ff6600.png'); // Source $width=imagesx($source); $height=imagesy($source); $im = imagecreatetruecolor($

我试图改变一个透明图像的颜色使用gd库我是新的gd库编译代码,它给出了错误 图像无法显示,因为它包含错误 这是我生成png图像的代码

<?php 
header("Content-type: image/png");
$source=imagecreatefrompng('ff6600.png');    // Source
$width=imagesx($source);    $height=imagesy($source);

$im = imagecreatetruecolor($width, $height);    // Our negative img in the making
$test = imagecolorallocate($im, 25,25,112);
for($y=0; $y < $height; $y++) {
    for($x=0; $x < $width; $x++) {

    $colors=imagecolorsforindex($source, imagecolorat($source, $x,$y));
        $test=imagecolorallocate($im, 25,25,112);
        imagesetpixel($im,$x, $y, $test);
    }
}
$imgname = time()."tiidi.png";

imagepng($im, $imgname);  
imagedestroy($im);



?>

如果您注释掉顶部的header函数,您可能会看到关于该函数的错误消息。我看不出我的图像上的代码有任何错误。这是整个代码吗?在创建图像之前(或之后)是否输出一些内容?

By
imagepng($im,$imgname)仅将图像保存到文件

只需添加另一个
imagepng($im)
,它没有文件名参数,将输出图像:

imagepng($im, $imgname);
imagepng($im);  
imagedestroy($im);

我检查过了,它对我有效。另外,请确保在header函数之前不输出任何内容。

我刚刚从代码中删除了php eng标记,它工作正常。我不知道它为什么会生成错误。

@donald123由于他设置的header,浏览器会认为它已损坏,并将显示该exect错误。Post owner:如果您临时禁用标题,您可以看到错误抱歉,这是我的错误,没有注意到我的服务器上没有安装GD扩展,只是安装了它。