[Image-SIG] Re: Image.putpalette() bug
Fredrik Lundh
fredrik@pythonware.com
Thu, 1 May 2003 14:09:13 +0200
"Derek Simkowiak" <dereks@realloc.net> wrote:
> I was testing my WalImagePlugin.py file, and got a strange
> message when I tried to "show()" it:
> class WalImageFile(ImageFile.ImageFile):
>
> format = "WAL"
> format_description = "Id Software Quake WAL texture map"
>
> def _open(self):
> ...
>
> Image.register_open("WAL", WalImageFile)
> Image.register_extension("WAL", ".wal")
this won't work: PIL requires file plugins to be able to identify a file
by looking at the contents, and there's no identifying information in
a WAL file.
why not just use the WalImageFile module from 1.1.4b1? (which is
pretty much identical to the one I posted, and appears to work with
all WAL samples I've checked).
in your program, you could do something like:
def image_open(filename):
if filename.endswith(".wal"):
im = WalImageFile.open(filename)
... get transparency setting ...
if transparency is not None:
im = im.convert("RGBA")
im.putalpha(Image.new("L", im.size, 255*transparency)
return im
else:
return Image.open(filename)
</F>