[reportlab-users] Image from MySQL table and drawImage

Robin Becker robin at reportlab.com
Thu Sep 6 09:08:42 EDT 2007


dimitri pater wrote:

>> I saw that you switched to using an intermediate file; can drawImage not take an

>> ImageReader instance? If not it's a buglet and should be fixed.

> But, maybe it's just me... Here is what I did with regard to ImageReader:

> cgebouw = StringIO()

> cgebouw.write(vb1[0][3].tostring())

> print cgebouw returns: <StringIO.StringIO instance at 0x019EEE18>

> c.drawImage(ImageReader(cgebouw), 35*mm, PAGE_HEIGHT-220*mm,

> width=None, height=None, mask=None)

> raises this error:

> File "C:\Python24\lib\site-packages\reportlab\lib\utils.py", line 537,

> in __init__

> a = str(ev.args[-1])+(' fileName='+fileName)

> TypeError: cannot concatenate 'str' and 'instance' objects

>

>> The problem with

>> using intermediates (at least on windows is knowing when to delete them).

> I have tried os.remove("temp.jpg") on several points in the code,

> haven't found the right one yet

>> --

>> Robin Becker

......
That must be a bug. According to me the current code for ImageReader does the
following

1) Check to see if the arg is a PIL image
2) checks to see if the object has a read action
3) attempts to open a local file with the arg as name
4) attempts to get a URL using the arg

When I run this script in the reportlab/test folder

############################################
from reportlab.lib.utils import ImageReader
from reportlab.pdfgen import canvas
from StringIO import StringIO
gif = open('pythonpowered.gif','rb').read()
c=canvas.Canvas('dongo.pdf')
c.drawImage(ImageReader(StringIO(gif)),144,144)
c.save()
############################################

Then it certainly works as expected; perhaps it's something that we fixed
recently or maybe it depends on the image being a particular type.
--
Robin Becker


More information about the reportlab-users mailing list