[reportlab-users] Troubles w/ ImageReader and PIL.Image

Robin Becker robin at reportlab.com
Tue Nov 21 05:37:28 EST 2006

Peter Kropf wrote:

> Hi -


> I'm trying to use ImageReader to put a logo in the footer section of a

> page. The logo is currently stored in a database, not in the file

> system. When I use PIL.Image as a parameter to ImageReader(), I get a

> NameError: global name 'im' is not defined. It looks like ImageReader

> is trying to get the actual filename of the file in


> self.fileName = im.fileName


> but is referencing the wrong object to do it. Should it be:


> self.fileName = self._image.fileName


> ?


> It also looks like this portion of the code isn't really tested much.

> All the tests create a new ImageReader using a filename instead of a

> PIL.Image object. Anyone else out there using ImageReader with

> PIL.Image?


> Thanks.


> - Peter

Someone contributed a fix to that problem recently. I thought it should be in
SVN already, but looking at the code it seems to be wrong. I think the relevant
code should really look like

if _isPILImage(fileName):
self._image = fileName
self.fp = fileName.fp
self.fileName = self._image.fileName
except AttributeError:
self.fileName = 'PILIMAGE_%d' % id(self)
Robin Becker

More information about the reportlab-users mailing list