Home > Archive > PERL Modules > January 2008 > GD: How to know image type? (JPEG, PNG, ..)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
GD: How to know image type? (JPEG, PNG, ..)
|
|
| Thomas Armstrong 2008-01-15, 8:01 am |
| Hi.
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.
| |
| Peter Ludikovsky 2008-01-15, 8:01 am |
| Thomas Armstrong wrote:
> Hi.
>
> 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.
>
a) Invoke the divine powers of file(1)
b) open the file & read the identifying characters [0][1][2]...
c) use File::Type;
HTH
/peter
[0] http://filext.com/file-extension/PNG
[1] http://filext.com/file-extension/GIF
[2] http://filext.com/file-extension/JPG
|
|
|
|
|