This works fine for generating an image from a buffer:

import base64

img_buffer = io.BytesIO()
pylab.savefig(img_buffer, format = 'png')
img_buffer.seek(0)

IMG(_src='data:image/png;base64,' + base64.b64encode(img_buffer.getvalue(), 
    _alt = 'image buffer not displaying'))

However, as Massimo points out, it's best if I switch to matplotlib. 
Thanks, guys!

On Monday, July 8, 2013 2:59:22 PM UTC-5, Anthony wrote:
>
> No, now you're trying to put the whole image in the URL query string. Just 
> let the URL point to the render_image function, and create the image in 
> that function. You cannot create the image in the same action that produces 
> the URL. First you have to return an HTML page with an image element. Then 
> the browser requests the src of the image element. The image must be 
> fetched in a separate request -- you cannot embed it in the original HTML 
> page that is returned.
>
> Anthony
>
> On Monday, July 8, 2013 3:43:22 PM UTC-4, Lamps902 wrote:
>>
>> Maybe I'm a bit confused on how to generate/stream the image, given the 
>> buffer. The following should work, right?
>>
>> def render_image():
>>    return Image.open(request.vars.image_buffer)
>>
>> ...
>> img_buffer = io.BytesIO()
>> pylab.savefig(img_buffer, format = 'png')
>> img_buffer.seek(0)
>>
>> return dict(img = IMG(_src=URL('render_image', vars=dict(image_buffer = 
>> img_buffer)), _alt = 'image buffer not displaying'))
>>
>> Or is there something other than Image.open() that's a better solution?
>>
>> On Monday, July 8, 2013 1:04:38 PM UTC-5, Anthony wrote:
>>>
>>>
>>> On Monday, July 8, 2013 12:49:19 PM UTC-5, Anthony wrote:
>>>>>
>>>>> The IMG() helper simply creates an HTML <img> element to be displayed 
>>>>> in the browser. The "src" attribute of an image element should be a URL 
>>>>> where the browser can request the image. You cannot pass an actual image 
>>>>> file object to the helper.
>>>>
>>>>
>>> Just make the "src" URL an action that generates the image and streams 
>>> it. 
>>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to