I can't open this PNG file with imagecreatefrompng()

非 Y 不嫁゛ 提交于 2019-12-10 03:39:36

问题


Here is a PNG file: http://imgur.com/NUl4v.png (Yes, never mind that it's a funny penguin with a sign...)

When running the following code:

imagecreatefrompng('http://imgur.com/NUl4v.png');

I get an error:

PHP Warning: imagecreatefrompng() [function.imagecreatefrompng]: Cannot read image data in /home/test/...

The PNG file seems to be fine - I can open it with different editors, and the Unix file command reports that it is:

PNG image, 640 x 360, 8-bit/color RGB, non-interlaced

PHP version: 5.2.13
GD version: bundled (2.0.34 compatible)


回答1:


I have no idea why, but the following works:

imagecreatefromstring(file_get_contents('http://imgur.com/NUl4v.png'));



回答2:


If you're trying to access it via a URL, see the allow_url_fopen configuration option. If this isn't enabled then PHP won't be able to load it from a remote resource.



来源:https://stackoverflow.com/questions/5175473/i-cant-open-this-png-file-with-imagecreatefrompng

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!