[Image-SIG] NT, IIS and png

Fredrik Lundh fredrik@pythonware.com
Thu, 10 May 2001 23:14:14 +0200


Anja Kipfer wrote:
> The error occurs a follows:
> 
> Image.save is called: apply(image.save, (sys.stdout, format), params)
> this calls PngImagePlugin._save(im, fp, filename, chunk=putchunk, check=0)
> this calls ImageFile._save(...)
> Here, the script crashes at line fh=fp.fileno(), whereby fp is the 
> passed-through parameter sys.stdout

- do you have more info about the crash?

(do you get an exception?  what does it say?)

- also, is sys.stdout an ordinary Python file object or something
else when you run under IIS?  if it's an ordinary file object, "print
sys.stdout" should give something like:

    <open file '<stdout>', mode 'w' at 00867520>

- if it's a non-standard object with a bad/broken file handle
connected to it, the following wrapper might help:

class NoRealFile:
    def __init__(self, file):
        self.file = file
    def __getattr__(self, name):
        if name == "fileno":
            raise AttributeError
        return getattr(self.file, name)

image.save(NoRealFile(sys.stdout), "PNG")

- if nothing else helps, save via a StringIO object:

buf = StringIO.StringIO()
image.save(buf, "PNG")
sys.stdout.write(buf.getvalue())

Cheers /F