Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with imagecreatefrompng (PHP)

Tags:

php

image

png

gd

gdlib

in one of my PHP projects, imagecreatefrompng complains, that the image "is not a valid PNG file".

Warning: imagecreatefrompng() [function.imagecreatefrompng]:
'/.../...png' is not a valid PNG file in /.../...php on line ...

I'm pretty sure, the file is valid, because I can open it in any program. So I was wondering what else could cause this warning.

Does anybody know the details behind imagecreatefrompng or has had a similar problem before?

Thanks for your help,

Timo

like image 987
Timo Avatar asked Feb 19 '10 11:02

Timo


2 Answers

Is it a PNG image? Run file against it, or try the fileinfo functions.

like image 90
Ignacio Vazquez-Abrams Avatar answered Oct 13 '22 20:10

Ignacio Vazquez-Abrams


Check this mime type of file you are going to upload by using below function:

mime_content_type($_FILES['product_img']['tmp_name'])

Image editors can often recognize file type by its contents, php might just try to use the file based on its mime-type. If it don't match then there's an error.

like image 44
jalpa Avatar answered Oct 13 '22 20:10

jalpa