[reportlab-users] Image from MySQL table and drawImage
    dimitri pater 
    dimitri.pater at gmail.com
       
    Wed Sep  5 17:11:55 EDT 2007
    
    
  
Okay thanks both,
this is what I came up with and it works inserting images in 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.
Another problem is that:
c.drawImage(fotogebouw, 35*mm, PAGE_HEIGHT-220*mm, width=None,
height=None, mask=None) raises this error:
File "C:\Python24\lib\site-packages\reportlab\platypus\flowables.py",
line 367, in __getattr__
    raise AttributeError(a)
AttributeError: getRGBData
thanks,
Dimitri
On 9/5/07, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Wed, 5 Sep 2007 10:16:33 +0200, "dimitri pater"
> <dimitri.pater at gmail.com> declaimed the following in
> gmane.comp.python.reportlab.user:
>
> > Sorry, I really should apologize...
> > inserting the image into the table doesn't work either. The text:
> > <StringIO.StringIO instance at 0x01443EB8>
> > is inserted into the table, not the image. I have no clue how to fix this...
> >
> > I thought it worked, but I had some 'old' code still uncommented, that
> > did the job
> > stupid of me, sorry about that
> >
> > On 9/5/07, dimitri pater <dimitri.pater at gmail.com> 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)
>
>         According to the documentation, a StringIO instance /starts at/
> position 0, so that .seek() looks redundant.
>
>         Do you ever "get" the value of the StringIO object?
>
>         thePhoto = foto.getvalue()
>
> (followed, perhaps, by foto.close() )
>
> > > 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'
> > >
>
>         Well, as it says, you passed it a StringIO /instance/, not the
> filename of an image file, or whatever. Perhaps you need to pass:
> fotogebouw.getvalue()  {presuming "image" can read a string as the
> data?}
>
>         ReportLab UG states that .drawImage() takes a filename, or of PIL
> Image object... So, I guess the next step would be how to convert the
> StringIO instance to an Image object instance.
>
>         Ah...  PIL Image.open
>
>         What do you get from:
>
> from PIL import Image
> foto = Image.open(StringIO(result[0][1]))
> --
>         Wulfraed        Dennis Lee Bieber               KD6MOG
>         wlfraed at ix.netcom.com           wulfraed at bestiaria.com
>                 HTTP://wlfraed.home.netcom.com/
>         (Bestiaria Support Staff:               web-asst at bestiaria.com)
>                 HTTP://www.bestiaria.com/
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
>
-- 
---
You can't have everything. Where would you put it? -- Steven Wright
---
please visit www.serpia.org
    
    
More information about the reportlab-users
mailing list