GD: How to know image type? (JPEG, PNG, ..)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm trying to create a Perl script which converts all files within a
directory into JPEG format. First, I read them using two lines
detecting extension (.jpg, .png, ...) but sometimes these files are
wrong and get this error message:
gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file:
starts with 0x89 0x50

Is there any method to get image type?
e.g.: GD::Image->getImageType("myfile.jpg")

Thank you very much.

Re: GD: How to know image type? (JPEG, PNG, ..)

Thomas Armstrong wrote:
Quoted text here. Click to load it

a) Invoke the divine powers of file(1)
b) open the file & read the identifying characters [0][1][2]...
c) use File::Type;



Site Timeline