[reportlab-users] Image-Compression: drawImage() using PIL -> PDF very large

Patrick Ulmer reportlab-users@reportlab.com
Fri, 19 Mar 2004 15:28:26 +0100


thank you for the very fast response. I have try to backport your 
changes in pdfutils.py, pdfimages.py, canvas.py and pdfdoc.py to 1.18, 
because with newer versions I get the "no getRGBData()" error when 
passing my PIL-Image to drawImage(). But PIL_Image has no method 
fp.read() or fp.seek(), like ImageReader (I think 1.19 use ImageReader 
instead of PILImage). No I found a hack for my problem under 1.18:

drawImage("/opt/zope/Extensions/pic.jpg", ......)

I want to try your changes in 1.19, but I don't know how to pass my 
PIL_Image to drawImage()? How can I get the ImageReader-object from my 
pil-object. It all so near but I can't get it :)

>Patrick I have made some changes to the back end image processing so
>that where possible we use JPEGS directly which should avoid the problem
>you report. The changed files are in CVS right now, but if you want I
>can package up the changes and email them to your for testing.
>>I have a size-problem with my pdf-file. I use reportlab 1.18 becaus of 
>>PIL. When I include a jpeg-file with drawImage(), the pdf-size is good, 
>>because the compressed image is inserted as it is. When I insert a 
>>PIL-jpeg-image, the rawdata compressed using zlib is inserted and the 
>>pdf-size is extrem larger. This is my source:
>># load data from zope
>>logo  = getattr(self.REQUEST.PARENTS[0].images.formulare, "headline.jpg")
>>img = PIL_Image.open(cStringIO.StringIO(str(logo.data)))
>># draw image
>>c.drawImage(img, 0, 0)
>>How can I solve this Problem?
>>1.) hack pdfimages.py?
>>2.) save img as tempfile and use c.drawImage(tmp, 0, 0)?
>>3.) somethind else?