PIL - Image.open() problem

Per Jensen dummy at net-es.dk
Sun Oct 28 16:28:38 EST 2001


Hi everybody.

It seems I don't know Python well enough yet. I have a problem with
Python Imaging Library which probably is simple. Only not for me!

Problem: I have a method in a classe which sometimes open a JPEG image,
and at other times do not.

When it doesn't work it is always in the same mode, which leads me to think
that I somehow don't initialize the PIL library.

The imports and method is shown below together with the stacktrace. Any
pointer as to where to look for the error is most welcome

Regards.
Per Jensen

--------------------------------------------

import os, sys, traceback
import string
from node import Node
from functions import printTraceback, trim, xmlString
from PIL import Image


    def getImage(self):
        "Return a PIL Image object of picture"
        try:
            if self.filename is None:  raise NE_NoFilename("Filename is None")
            if self.filename == "":  raise NE_NoFilename("Filename is empty")
            if self.picture is None:
                print "Opening picture: \""  + self.filename + "\""
                self.picture = Image.open(self.filename)
                print "Opening succeeded!"
            return self.picture
        except:
            printTraceback()
            return None


Result: 
---------------------------------------------
Opening picture: "1.jpg"
Traceback (most recent call last):
  File "./picture.py", line 155, in getImage
  self.picture = Image.open(self.filename)
  File "/var/tmp/python-imaging-root//usr/lib/python2.0/site-packages/PIL/Image.py", line 871, in open
  prefix = fp.read(16)
AttributeError: read
--------------------------------------------



More information about the Python-list mailing list