[reportlab-users] TIFF-files with group 4 encoding and image-object in drawImage

Knut Hansen knut.hansen at tromso.online.no
Sun Dec 7 15:47:33 EST 2008


This is two related problems. If I try to put a TIFF-image with group 4
encoding on a reportlab canvas with drawImage(c,'MyFile.TIF',0,0) I get
an argument error. It seems the image-handling routine in ReportLab
cannot handle TIFF-files with group 4 encoding. Googling the problem I
see I'm not alone. So first question:

Is there any patch or new version of reportlab that will fix this?

To try to work around this problem I have found that wx and PIL can help
(I need to use PIL to modify the images anyway, so that is no overhead).
According to the documentation drawImage will accept either a filename
or an image object. But when I try the following code, it fails:

wx_img = wx.Image('MyFile.TIF', wx.BITMAP_TYPE_TIF)
pil = Image.new('RGB',(wx_img.GetWidth(), wx_img.GetHeight()))
pil.fromstring(wx_img.GetData())
Canvas.drawImage(c,pil,0,0)

The error message is:

Traceback (most recent call last):
File "tilpdf.py", line 58, in <module>
make_page(c,filer[i], i)
File "tilpdf.py", line 43, in make_page
z = Canvas.drawImage(c,pil,0,0)
File "/usr/lib/python2.5/site-packages/reportlab/pdfgen/canvas.py", line
629,in drawImage
imgObj = pdfdoc.PDFImageXObject(name, image, mask=mask)
File "/usr/lib/python2.5/site-packages/reportlab/pdfbase/pdfdoc.py",
line 1842, in __init__
self.loadImageFromSRC(source)
File "/usr/lib/python2.5/site-packages/reportlab/pdfbase/pdfdoc.py",
line 1891, in loadImageFromSRC
fp = im.jpeg_fh()
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 494, in
__getattr__
raise AttributeError(name)
AttributeError: jpeg_fh

But if I write the PIL image to a file and read that with drawImage
everything is OK. So, why doesn't drawImage accept my image object?

Knut


More information about the reportlab-users mailing list