[reportlab-users] Still confused about PIL Image objects

Robin Becker robin at reportlab.com
Wed May 11 12:03:07 EDT 2005

Ian Sparks wrote:
> It used to be that PIL Image objects could be passed to the canvas.drawImage() method. Then there was a change in ReportLab which made this fail with an error related to "getRGBData()".
> I understand that this was done to reduce the requirement to have PIL installed. Fair enough.
> I'm using reportlab 1.20. I have a PIL Image object that I want to pass to canvas.drawImage(). I'm using PIL because I often need to resize or modify the image in some way before I write it into the PDF.
> Right now I'm doing this :
> 		#im is the PIL Image object
>             filename = 'temp_im.bmp'
>             im.save(filename) #This is an annoying hack, save to a file to get it re-imported  
>             canvas.drawImage(filename,....)
>             os.remove(filename) #Remove it again
> There has to be a better way. Someone please enlighten me?

in 1.20 you cannot use a PIL object directly. After some discussion we agreed to 
allow the ImageReader class to accept a PIL image. That is currently in SVN.

The question then arises as to whether we should call ImageReader() on things 
passed into the canvas methods. That would take us back to the old position 
where you could pass in a string or an object to drawImage. We don't want to be 
testing this stuff all over the codebase. I think we want to convert everything 
to an ImageReader and then use that internally.

If we pass in an ImageReader that should also be relatively easy ie 
ImageReader(imagereader) should return a borg version of imagereader.
Robin Becker

More information about the reportlab-users mailing list