Re: load Image() from embedded python

Michael Hipp <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Message-ID <[email protected]>
Thanks Andy.

It does indeed work. For anyone else that might try this, here's what I did...

Use bin2py to convert the jpg image file to python:
https://github.com/MarioVilas/shellcode_tools/blob/master/bin2py.py

    > bin2py logo.jpg -o logo.py

Then put in the program something like this:

     import logo
     import StringIO
     from reportlab.platypus import Image

          img = Image(StringIO(logo.logo), width=48, height=48)

Works swimmingly and now I don't have to package the logo.jpg file as a data 
file with the program.

Note that I was not able to get ReportLab Image() to work with the output from 
wxPython's img2py utility as I had originally intended, hence the use of bin2py.

Michael


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
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.