Nathan Osman
Nathan Osman

Reputation: 73165

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

Here is a PNG file: https://i.sstatic.net/AHOgE.png (Yes, never mind that it's a funny penguin with a sign...)

When running the following code:

imagecreatefrompng('https://i.sstatic.net/AHOgE.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)

Upvotes: 7

Views: 13677

Answers (2)

Nathan Osman
Nathan Osman

Reputation: 73165

I have no idea why, but the following works:

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

Upvotes: 15

Hamish
Hamish

Reputation: 23316

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.

Upvotes: 4

Related Questions