<!DOCTYPE html>
<html>
    <head>
        <title>test</title>
        <meta http-equiv="Content-type" content="text/html">
    </head>
    <body>
        hello
        <?php
            $image=imagecreatetruecolor(100,100);
            $red=imagecolorallocate($image,0xff,0x00,0x00);
            imagefill($image,0,0,$red);
            header('Content-type:image/png');
            imagepng($image);
            imagedestroy($image);
        ?>
    </body>
</html>

问题出在Content-type:image/png

用window的记事本编辑,源代码文件的编码utf8会有bom头、是不是这样,还需要验证、