[reportlab-users] load Image() from embedded python
robin at reportlab.com
Sun Feb 9 05:12:45 EST 2014
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
ImageReader is acceptable to drawImage & a bytes io object is
acceptable to ImageReader (I think).
On 8 February 2014 17:54, Michael Hipp <michael at redmule.com> 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
> canvas.drawImage(StringIO('embedded stuff'), ...)
> I would be really helpful to be able to embed these things.
> I'm using reportlab 3.0a1 BTW.
> line 920, in drawImage
> imgObj = pdfdoc.PDFImageXObject(name, image, mask=mask)
> line 2086, in __init__
> ext = os.path.splitext(source).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
> 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 <michael at redmule.com> wrote:
>>> In the reportlab.platypus Image flowable, is it possible to load the
>>> from an image embedded as binary in the python code? The only api for
>>> seems to depend on a filename.
>>> I'd prefer not to have to lug around things like logos and icons with my
>>> reportlab-users mailing list
>>> reportlab-users at lists2.reportlab.com
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
More information about the reportlab-users