[reportlab-users] problem with PIL 1.1.7 and ReportLab 2.2

Robin Becker robin at reportlab.com
Thu Dec 10 12:39:36 EST 2009


On 10/12/2009 16:58, Bill Janssen wrote:

> Folks, I've recently upgraded to PIL 1.1.7, and I'm suddenly seeing an

> issue with ReportLab that I hadn't before. Here's my code:

>

> c = canvas.Canvas(outputfile,

> pagesize=(5 * inch, 3 * inch))

> border = 0.3 * inch

> x = border

> y = (3 * inch) - (2 * border)

> iconwidth = 0.5 * inch

> iconheight = iconwidth / self._CARDIMAGEASPECT

> c.drawImage(_CARDIMAGEFILEPATH,

> (5 * inch - border - iconwidth),

> (3 * inch - border - iconheight),

> iconwidth, iconheight)

>

> The path specified by _CARDIMAGEFILEPATH does exist and is readable and

> is a valid PNG (this code has been working fine for over a year).

>




>

> And here's the stack trace:

>

> [... my frames omitted ...]

> thr008: File "/opt/GoodStuff/UpLib/lib/python2.5/site-packages/reportlab/pdfgen/canvas.py", line 623, in drawImage

> thr008: imgObj = pdfdoc.PDFImageXObject(name, image, mask=mask)

> thr008: File "/opt/GoodStuff/UpLib/lib/python2.5/site-packages/reportlab/pdfbase/pdfdoc.py", line 1994, in __init__

> thr008: self.loadImageFromA85(src)

> thr008: File "/opt/GoodStuff/UpLib/lib/python2.5/site-packages/reportlab/pdfbase/pdfdoc.py", line 1998, in loadImageFromA85

> thr008: imagedata = map(string.strip,pdfutils.makeA85Image(source,IMG=IMG))

> thr008: File "/opt/GoodStuff/UpLib/lib/python2.5/site-packages/reportlab/pdfbase/pdfutils.py", line 35, in makeA85Image

> thr008: raw = img.getRGBData()

> thr008: File "/opt/GoodStuff/UpLib/lib/python2.5/site-packages/reportlab/lib/utils.py", line 650, in getRGBData

> thr008: self._dataA = ImageReader(im.split()[3])

> thr008: File "/opt/GoodStuff/UpLib/lib/python2.5/site-packages/PIL/Image.py", line 1497, in split

> thr008: if self.im.bands == 1:

> thr008: AttributeError: 'NoneType' object has no attribute 'bands'

>

> Anyone see what's going wrong here? What do I need to change?

>

> If you'd like to, you can try it yourself by downloading UpLib from

> http://uplib.parc.com and building it with various combos of ReportLab

> and PIL.

>

> Bill

........

well since I assume it worked with < 1.1.7 it's likely the problem is with some
change in PIL.

I haven't tried PIL 1.1.7 the latest I see is 1.1.6; is this code failing with
all images? Looking at the beta stuff I see some changes were made for the PNG
format so perhaps they affected this attempt at getting information about the
alpha channel. Not having messed about I'm guessing that im.split() isn't
returning what it used to. Looking at the code near the failure

im = self._image
mode = self.mode = im.mode
if mode=='RGBA':

it seems as though the image has been identified as RGBA and then we're trying
to use im.split() to create a new image representing the alpha channel (so it
can be used as a mask later on).
--
Robin Becker


More information about the reportlab-users mailing list