[reportlab-users] Image from MySQL table and drawImage

Robin Becker robin at reportlab.com
Wed Sep 5 04:55:10 EDT 2007


dimitri pater wrote:

> Hello,

>

> I use this code to insert an image (BLOB) from MySQL into a table:

> from StringIO import StringIO

> foto=StringIO(result[0][1])

> foto.seek(0)

> and the photo is inserted into the table, that works very well. I was

> very glad when I managed to that :-), there are 100's of thumbnails in

> the DB...

> However, in another part of my applaication (where I create the first

> page (the cover)) I am trying to do this:

> fotogebouw=StringIO(result[0][2])

> fotogebouw.seek(0)

> c.drawImage(fotogebouw, 35*mm, PAGE_HEIGHT-220*mm, width=None,

> height=None, mask=None)

> results in an error:

> c.drawImage(fotogebouw, 35*mm, PAGE_HEIGHT-220*mm, width=None,

> height=None, mask=None)

> File "C:\Python24\lib\site-packages\reportlab\pdfgen\canvas.py",

> line 584, in drawImage

> rawdata = image.getRGBData()

> AttributeError: StringIO instance has no attribute 'getRGBData'

>

> Any ideas or clues someone? The c.drawImage used to work with a image

> stored on a local drive, but I need to have all data in the DB, also

> the images.

>

> Thanks, your help is appreciated!

> Dimitri

>

>


I believe the argument to drawImage should either be a filename or an instance
of a reportlab.lib.utils.ImageReader. The ImageReader can take a filelike object
or a filename.
--
Robin Becker


More information about the reportlab-users mailing list