imghdr.what failed to identify JPEG

Steven Taschuk staschuk at telusplanet.net
Sun Jun 8 01:14:49 EDT 2003


Quoth Arsenal:
> I have 206 jpg files. And imghdr.what returns 'None' for 52 of them,
> and I found that actually those 52 files can be viewed perfectly with
> an image viewer (xnview), and xnview also identifed them as JPEG
> TrueColor(v1.1) in the File Properties.
> 
> Is it true that the jpg file format has more than one "identifying
> signature" which the imghdr.what function didn't yet incorporate, and
> hence the false negatives?

That seems a reasonable guess.

A glance at the source shows that imghdr.what identifies JPEGs
this way:
        if h[6:10] == 'JFIF':
That is, the test is whether bytes 6 through 9 inclusive of the
file are 'JFIF'.  (As the documentation notes, it identifies JPEGs
in JFIF format specifically.)

Do your files have this property?  If not, what are these bytes?

(My magic(4), for comparison, identifies JPEGs thus:
    0       beshort         0xffd8          JPEG image data
    >6      string          JFIF            \b, JFIF standard
    >6      string          Exif            \b, EXIF standard
)

-- 
Steven Taschuk                           staschuk at telusplanet.net
"I'm always serious, never more so than when I'm being flippant."
                            -- _Look to Windward_, Iain M. Banks





More information about the Python-list mailing list