Finding MIME type for a data stream

Tobiah toby at
Fri Mar 9 18:53:30 CET 2012

> Something like the following might be worth a go:
> (untested)
> from PIL import Image
> img =
> print img.format

This worked quite nicely.  I didn't
see a list of all returned formats though
in the docs.  The one image I had returned


So I'm doing:

mime_type = "image/%s" % img.format.lower()

I'm hoping that will work for any image type.



More information about the Python-list mailing list