I am rather new to python and have a problem with the save
function of the Pillow fork of PIL.
With this minimal example
import Image
im = Image.new("RGB", (200, 30), "#ddd")
im.save("image.png")
I get the following error:
File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 1667, in save
raise KeyError(ext) # unknown extension
KeyError: '.png'
The corresponding lines in the save
function are
preinit()
[...]
try:
format = EXTENSION[ext]
except KeyError:
raise KeyError(ext) # unknown extension
I looked at the EXTENSION
array and detected that it is empty, although it should be initialized in preinit()
by for example from PIL import PngImagePlugin
. PngImagePlugin.py
calls Image.register_extension("PNG", ".png")
. Watching the array inside this function or inside PngImagePlugin
it is indeed filled with file extensions.
Putting print(EXTENSION)
right before the try-except-block however shows an empty EXTENSION
array.
(Same issue with the SAVE
array a few lines down in the save
function.)
Any help is appreciated.
EDIT: I recently upgraded from OpenSuse 13.1. to 13.2. It worked fine in 13.1 but not in 13.2.
You need to write this instead: