imagecreatefrompng():'/ home / subuntu / dv8.png'不是有效的PNG文件

时间:2011-07-23 04:01:20

标签: php image png gd

我的代码:

    $filepath = '/home/ubuntu/dv8.png';
    echo "mime content type: " .mime_content_type ($filepath) . "<br />";
    $image_src = imagecreatefrompng($filepath);
    print_r($image_src);

输出:

mime content type: image/png
Warning: imagecreatefrompng(): '/home/ubuntu/dv8.png' is not a valid PNG file in /var/www/test.php on line 2

任何想法为什么我会得到这个?它可能与我的PHP版本有关吗? 5.3.2

phpinfo()并在GD部分下列出:

PNG Support enabled

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

当我使用未以“索引”模式保存的PNG文件时,主要是透明度问题。

要将PNG从RGB模式更改为索引模式,请在gimp中打开它并转到 图像 - &GT; MODE-&GT; INDEXED

再次导出。看看是否能解决问题。