[Tutor] can not get subtype?

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Oct 21 19:32:02 CEST 2004


On Thu, 21 Oct 2004, Ertl, John wrote:

> I have recently transferred everything including rebuilding python (same
> version as old system 2.3.4) and now the email MIMEImage can not
> automatically figure out the image type (it worked on the old system).
> I had to add '_subtype="png"' to the MIMEImage line (see below).  For
> now I guess that is OK but I am wondering if something else is going on
> that I should know about.  This also precludes me from producing other
> types without changing my code.


Hi John,


I looked at the MIMEImage code --- it uses the 'imghdr' Standard Library
module to try to guess what a particular byte stream might be.

    http://www.python.org/doc/lib/module-imghdr.html


My best guess about the problem is that 'imghdr' isn't recognizing your
files anymore.


Here's the particular test that 'imghdr' does for pngs:

###
def test_png(h, f):
    if h[:8] == "\211PNG\r\n\032\n":
        return 'png'
###


Hmmm... and that seems to be correct.  From the PNG format page, I'm
reading that every PNG file needs to have an eight byte header with the
following hexadecimal values: 89h 50h 4Eh 47h 0Dh 0Ah 1Ah 0Ah.


Can you check to see if imghdr is still correctly identifying your png
files as pngs?


Good luck!



More information about the Tutor mailing list