images on the web

Michael Ströder michael at
Fri Jun 20 08:52:55 CEST 2008

Matt Nordhoff wrote:
> Matt Nordhoff wrote:
>> You could use data: URIs [1].
>> For example, a 43-byte single pixel GIF becomes this URI:
>> They don't have universal browser support, but that might not be a
>> problem in this case.
>> As for generating them with Python, I'm not sure... I just used Hixie's
>> data: URI kitchen [2] for the above example.
>> [1] <>
>> [2] <>
> Oh.. As <>
> shows, the reason I couldn't find a data: URI Python library is because
> they're utterly trivial to generate:
> import base64
> import urllib
> raw_data = create_gif()
> uri = 'data:image/gif;base64,' + urllib.quote(base64.b64encode(raw_data))
> (And it's even simpler if you leave out the base64-encoding.)

The caveat with URL schema data: is that the amount of data to be 
transferred is significantly higher than including HTML tag <img src=""> 
in your HTML source and let the browser fetch the raw binary image data 
in a separate HTTP request (you also have to serve from your web 

Ciao, Michael.

More information about the Python-list mailing list