Re: load Image() from embedded python
Andy Robinson <[email protected]>
| Newsgroups | gmane.comp.python.reportlab.user |
|---|---|
| Message-ID | <CABjtApvN15MTSMpS6jrs3xSd5t5DR_-8QzxUv6NF9oJDpOL=DQ@mail.gmail.com> |
We'd better make sure we get this right in the docs... On 9 February 2014 18:06, Robin Becker <[email protected]> wrote: > Yes I thing you can pass either an ImageReader or a filename, but not > a file like object into drawImage. > > On 9 February 2014 15:10, Michael Hipp <[email protected]> wrote: >> I'm using Python 2.7.6 on windows. I tried both cStringIO and StringIO with >> no luck. But the combo of ImageReader and getBytesIO works great. Thank you. >> >> Michael >> >> >> >> On 2/9/2014 4:12 AM, Robin Becker wrote: >>> >>> Not sure if this is with python 2.7 or 3.3, but there are differences >>> in the way StringIO works in the two dialects. In practice I think for >>> any kind of image object we ought to be reading in binary so StringIO >>> is off the table. Can you try passing an ImageReader instance to the >>> canvas. That would look like >>> >>> >>> from reportlab.lib.utils import ImageReader, getBytesIO >>> >>> ....... >>> >>> >>> canvas.drawImage(ImageReader(getBytesIO('embedded stuff'))) >>> >>> >>> >>> ...... >>> >>> ImageReader is acceptable to drawImage & a bytes io object is >>> acceptable to ImageReader (I think). >>> >>> On 8 February 2014 17:54, Michael Hipp <[email protected]> wrote: >>>> >>>> As noted in my previous reply I was able to make this work great with the >>>> flowable Image(). >>>> >>>> Now I'm doing something like this, and getting the exception below. Any >>>> suggestions? >>>> >>>> canvas.drawImage(StringIO('embedded stuff'), ...) >>>> >>>> I would be really helpful to be able to embed these things. >>>> >>>> I'm using reportlab 3.0a1 BTW. >>>> >>>> Thanks, >>>> Michael >>>> >>>> File >>>> >>>> "c:\dev\virtenvs\oldworldblack\lib\site-packages\reportlab\pdfgen\canvas.py", >>>> line 920, in drawImage >>>> imgObj = pdfdoc.PDFImageXObject(name, image, mask=mask) >>>> File >>>> >>>> "c:\dev\virtenvs\oldworldblack\lib\site-packages\reportlab\pdfbase\pdfdoc.py", >>>> line 2086, in __init__ >>>> ext = os.path.splitext(source)[1].lower() >>>> File "c:\dev\virtenvs\oldworldblack\lib\ntpath.py", line 190, in >>>> splitext >>>> return genericpath._splitext(p, sep, altsep, extsep) >>>> File "c:\dev\virtenvs\oldworldblack\lib\genericpath.py", line 91, in >>>> _splitext >>>> sepIndex = p.rfind(sep) >>>> AttributeError: StringIO instance has no attribute 'rfind' >>>> >>>> >>>> >>>> >>>> On 1/29/2014 1:47 AM, Andy Robinson wrote: >>>>> >>>>> >>>>> I think that everywhere we accept a filename, we also accept a >>>>> file-like object. So you could store it as some kind of escaped >>>>> binary string in your source code, then wrap it in a StringIO and pass >>>>> that to the platypus Image. >>>>> >>>>> I'm not in a programming environment now but if this is not clear we >>>>> can post a code snippet later in the day... >>>>> >>>>> - Andy >>>>> >>>>> >>>>> >>>>> On 29 January 2014 00:50, Michael Hipp <[email protected]> wrote: >>>>>> >>>>>> >>>>>> In the reportlab.platypus Image flowable, is it possible to load the >>>>>> image >>>>>> from an image embedded as binary in the python code? The only api for >>>>>> Image >>>>>> seems to depend on a filename. >>>>>> >>>>>> I'd prefer not to have to lug around things like logos and icons with >>>>>> my >>>>>> program. >>>>>> >>>>>> Thanks, >>>>>> Michael >>>>>> _______________________________________________ >>>>>> reportlab-users mailing list >>>>>> [email protected] >>>>>> http://two.pairlist.net/mailman/listinfo/reportlab-users >>>>> >>>>> >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> reportlab-users mailing list >>>> [email protected] >>>> http://two.pairlist.net/mailman/listinfo/reportlab-users >>> >>> >>> >>> >> >> _______________________________________________ >> reportlab-users mailing list >> [email protected] >> http://two.pairlist.net/mailman/listinfo/reportlab-users > > > > -- > Robin Becker > _______________________________________________ > reportlab-users mailing list > [email protected] > http://two.pairlist.net/mailman/listinfo/reportlab-users -- Andy Robinson Managing Director ReportLab Europe Ltd. Thornton House, Thornton Road, Wimbledon, London SW19 4NG, UK Tel +44-20-8405-6420