base64 encode your pngs (in python) for your webapps
Posted by Senthil Kumaran | Filed under python
In web application development you may want to use an image in a base64 encoded fashion rather than loading the image directly.
The img src tag supports a data:image/png;base64 format and browsers can display the image for you.
Look here for an example of how this is done - http://jsfiddle.net/phoe6/vJ3pM/
Now, in order to convert an image from .png format to data:image;base64 format, you can do it like this using python.
import base64
with open('golden_stars.png','rb') as img:
encoded_str = base64.b64encode(img.read())