[Image-SIG] Getting format from file extension and mime types

Vlastimil Zíma vlastimil.zima at nic.cz
Thu Jul 14 10:14:41 CEST 2011


Hi,

recently I encountered problem with PIL on saving images which filename 
had no extension. When I tried to save such image, PIL raises KeyError

   File "/usr/lib/python2.6/dist-packages/PIL/Image.py", line 1423, in save
     raise KeyError(ext) # unknown extension

KeyError: ''


What is proper solution for such problem? I found out that I should 
specify format argument, so I wanted to use PIL's MIME dictionary, but I 
found out that it can not store multiple mime types for image format 
identifier, which is not very useful.

I would have to create mine dictionary that converts mime types to PIL 
formats, which I would like to avoid.

Any suggestions?

Vlastimil Zíma


More information about the Image-SIG mailing list