Hi,
the following code works when inserting images in reportlab tables:

(result4 is a query result)
a=0
for i in result4:
           cfoto = StringIO()
           cfoto.write(result4[a][9].tostring())
           dfoto = cfoto.getvalue()
           fileFoto = open(str(a)+'temp.jpg','wb')
           fileFoto.write(dfoto)
           fileFoto.close()
           foto = Image(str(a)+'temp.jpg')
           a+=1

          Do stuff here (insert the Image)

The problem with this code is that I need to create a unique file
(str(a)+'temp.jpg'), I tried to use a single temp.jpg but it kept
using the data from the first record. Tried flush(), truncate(0), but
it didn't work. (My mistake probably ;-)
But the images show in the PDF so that's fine for now.

On 9/5/07, dimitri pater <[EMAIL PROTECTED]> wrote:
> ---------- Forwarded message ----------
> From: dimitri pater <[EMAIL PROTECTED]>
> Date: Sep 5, 2007 9:13 PM
> Subject: Re: StringIO MySQL data blob Image problem
> To: Tim Golden <[EMAIL PROTECTED]>
>
>
> > Well, I'm mystified. Not by your results: that exactly what I
> > expected to get, but because you're doing everything *except*
> > manipulating an image and putting it into a PDF via ReportLab.
> >
> Dear Tim,
> you are right of course, I have been trying to put the StringIO in a temp 
> file:
> cfoto=StringIO
> cfoto.write(result[0][1].tostring())
> dfoto=cfoto.getvalue()
> fileFoto=open('temp.jpg','wb')
> fileFoto.write(dfoto)
>
> and indeed, the blob from MySQL is saved as an image!
> however,
> foto= Image('temp.jpg')
> and inserting foto into a table results in:
> x = struct.unpack('B', image.read(1))
> error: unpack str size does not match format
> oh, well... still needs some work
> BTW: I used 'local' images before (I mean they did not originate from
> a DB), that worked well in Reportlab's tables.
> Thanks, I am getting there (I think)
>
>
> --
> ---
> You can't have everything. Where would you put it? -- Steven Wright
> ---
> please visit www.serpia.org
>


-- 
---
You can't have everything. Where would you put it? -- Steven Wright
---
please visit www.serpia.org
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to