Misha Moroshko
Misha Moroshko

Reputation: 171419

How to create PNG thumbnail if "imagecreatefrompng()" fails?

I start to create a PNG thumbnail by using this function:

$image = imagecreatefrompng("http://imagenic.net/images/pfujz9j5juav1qrex00.png");

However, it says:

'http://imagenic.net/images/pfujz9j5juav1qrex00.png' is not a valid PNG file

It works OK with other PNG images, so I guess something is wrong with this specific picture.

What can I do in this situation ?

Is there another way to create the thumbnail ?

(BTW, I found this picture in the web.)

Upvotes: 1

Views: 1999

Answers (3)

Scuzzy
Scuzzy

Reputation: 12322

Using getimagesize() returns a mime value of image/jpeg, you can call this function to determine which imagecreatefrom... function to call next.

Upvotes: 6

Dean Harding
Dean Harding

Reputation: 72668

According to Firefox, that image is actually a JPEG image. Someone's just given it the wrong extension. You can use the finfo_file function to check the actual type of the file by sniffing it's header.

Upvotes: 4

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799190

Try one of the other imagecreatefrom*() functions. Or use the fileinfo functions and stop guessing.

Upvotes: 2

Related Questions