Determining if file is valid image file

André andre.roberge at gmail.com
Thu Aug 2 10:49:32 EDT 2007


On Aug 2, 11:38 am, kyoso... at gmail.com wrote:
> On Aug 2, 9:35 am, Thomas Jollans <tho... at jollans.com> wrote:
>
>
>
> > On Thursday 02 August 2007, André wrote:
>
> > > On Aug 2, 11:14 am, André <andre.robe... at gmail.com> wrote:
> > > > Other than installing PIL, is there a "simple" way using Python only
> > > > to determine if a file is a valid image file?
>
> > > > I'd be happy if I could at least identify valid images files for gif,
> > > > jpeg and png.   Pointers to existing modules or examples would be
> > > > appreciated.
>
> > > > The reason why I'd prefer not using PIL is that I'd like to bundle
> > > > such a function/module in my app.
>
> > > I should have added: I'm interesting in validating the file *content*
> > > - not the filename :-)
>
> > The file name has nothing to do with the type :-P
>
> > A straightforward way you won't like: read the specs for all formats you're
> > interested in and write the function yourself ;-)
>
> Use the md5 module to create checksums. Links below:
>

Sorry, I fail to see how this helps me to identify if a file I
retrieve from somewhere is a valid image file...

> http://www.peterbe.com/plog/using-md5-to-check-equality-between-fileshttp://effbot.org/librarybook/md5.htmhttp://docs.python.org/lib/module-md5.html
>
> Larry is right too...what's wrong with bundling PIL or any third party
> module?
>

Why not bundling PIL?: Because I'm trying to keep the size of my app
as small as possible.
I don't mind bundling some other modules from third parties (in fact,
I already do include
three modules from ElementTree...).

André

> Mike





More information about the Python-list mailing list