Thursday, 17 February 2011

Images, python and base64

Kari - embeded as base64 :)
Look at the image on the left. It's embedded. The idea is very simple.

Open some image file.

Read it in a string.

Encode it with base64.

Now you can use the result as src in the img tag. This image can be used in html email messages or can be used in the css.



Here is some python code:

png_file = open('applets-screenshooter.png','rb')
png_txt = png_file.read()
png_img = png_txt.encode('base64')

Look at the result

If you have any ideas on how to use such images, please share in the comments.

4 comments:

  1. In next link is shown the RFC of using embed images, and not only images
    http://www.faqs.org/rfcs/rfc2397.html

    ReplyDelete
  2. The RFC is too old. But here you can find some information about Data URI scheme.

    ReplyDelete
  3. Also look at this site. Here you can find out on which browser this will work.

    ReplyDelete