I'm grabbing Base64 encoded text from a database and which to decode =
and display it has a picture (jpeg). How should I do this?
I can get the text and decode it OK, I just don't know how to display =
the resulting image.
Colin Gillespie wrote:
> I'm grabbing Base64 encoded text from a database and which to
> decode and display it has a picture (jpeg). How should I do this?
> I can get the text and decode it OK, I just don't know how to
> display the resulting image.
It sounds like you need something like this example:
All it does is set the content type header to let the browser know you're
sending an image not an HTML page (in your case you'll want image/jpeg not
image/gif) and then outputs the image file content. If you've already got
the image data in a variable (after extracting it and decoding from base64)
use that instead of the include.dump(...) bit.
If you have a file like this called image.spy you can then use it like any
other image URL, eg:
<img src="image.spy" alt="..." />
This is assuming your data is already encoded in JPEG format, so you just
need to output it. If it's in another format you'll need to convert it
first - the Python Imaging Library may help: