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


php image generating error cant display because it contain errors

我正在尝试使用 gd 库更改透明图像的颜色,我是 GD 库的新手 编译代码 它给出了错误图像 http://localhost/gdlib/gd.php 无法显示,因为它包含错误这是我生成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);

?>

如果您注释掉顶部的标头函数,您可能会看到有关此的错误消息。我在我的图像上看到该代码没有错误。这是整个代码并在创建图像之前(或之后)输出一些东西吗?

通过imagepng($im, $imgname);,您只需将图像保存到文件。

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

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

检查了它,它对我有用。还要确保在标头函数之前不输出任何内容。

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

相关文章: