Finding MIME type for a data stream

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


> Something like the following might be worth a go:
> (untested)
> 
> from PIL import Image
> img = Image.open(StringIO(blob))
> 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

PNG

So I'm doing:

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

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

Thanks,

Tobiah



More information about the Python-list mailing list