Click here to get back home

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

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
GD: How to know image type? (JPEG, PNG, ..) Thomas Armstrong 01-15-2008
Posted by Thomas Armstrong on January 15, 2008, 6:36 am
Please log in for more thread options
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.


Posted by Peter Ludikovsky on January 15, 2008, 7:56 am
Please log in for more thread options
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

Similar ThreadsPosted
Module for manipulating JPEG image January 4, 2007, 12:53 pm
How to detect an image type with GD November 8, 2006, 12:10 pm
HTTP::Request::Form - Problem pressing input type=image button February 1, 2005, 7:56 am
ImageMagick and Xitami jpeg/bmp issue June 28, 2006, 9:40 am
Manipulating ANY type of email January 3, 2006, 5:03 pm
Ip address Data Type DBI May 10, 2006, 4:38 pm
Term::Cap -- Setting terminal type under Windows XP May 24, 2006, 1:46 pm
Term::Cap -- Setting terminal type under Windows XP May 29, 2006, 9:22 pm
[RFC] GD-Image-CopyIFS May 14, 2005, 3:42 pm
image magick through apt-get November 27, 2004, 5:48 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap