473,382 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

images on the web

I'm creating a data plot and need to display the image to a web page.
What's the best way of doing this without having to save the image to
disk? I already have a mod_python script that outputs the data in
tabular format, but I haven't been able to find anything on adding a
generated image.
Jun 27 '08 #1
5 1635
chris wrote:
I'm creating a data plot and need to display the image to a web page.
What's the best way of doing this without having to save the image to
disk? I already have a mod_python script that outputs the data in
tabular format, but I haven't been able to find anything on adding a
generated image.
You could use data: URIs [1].

For example, a 43-byte single pixel GIF becomes this URI:

<data:image/gif;base64,R0lGODlhAQABAIAAAP%2F%2F%2F%2F%2F%2F%2F yH5BAEAAAEALAAAAAABAAEAAAICTAEAOw%3D%3D>

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] <http://tools.ietf.org/html/rfc2397>
[2] <http://software.hixie.ch/utilities/cgi/data/data>
--
Jun 27 '08 #2
Matt Nordhoff wrote:
chris wrote:
>I'm creating a data plot and need to display the image to a web page.
What's the best way of doing this without having to save the image to
disk? I already have a mod_python script that outputs the data in
tabular format, but I haven't been able to find anything on adding a
generated image.

You could use data: URIs [1].

For example, a 43-byte single pixel GIF becomes this URI:

<data:image/gif;base64,R0lGODlhAQABAIAAAP%2F%2F%2F%2F%2F%2F%2F yH5BAEAAAEALAAAAAABAAEAAAICTAEAOw%3D%3D>

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] <http://tools.ietf.org/html/rfc2397>
[2] <http://software.hixie.ch/utilities/cgi/data/data>
Oh.. As <http://bitworking.org/news/Sparklines_in_data_URIs_in_Python>
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.)
--
Jun 27 '08 #3
chris wrote:
I'm creating a data plot and need to display the image to a web page.
What's the best way of doing this without having to save the image to
disk? I already have a mod_python script that outputs the data in
tabular format, but I haven't been able to find anything on adding a
generated image.
Does your web application has session handling? Then you could save the
image in the session and server the separate HTTP request sent by the
browser.

Ciao, Michael.
Jun 27 '08 #4
Matt Nordhoff wrote:
Matt Nordhoff wrote:
>You could use data: URIs [1].

For example, a 43-byte single pixel GIF becomes this URI:

<data:image/gif;base64,R0lGODlhAQABAIAAAP%2F%2F%2F%2F%2F%2F%2F yH5BAEAAAEALAAAAAABAAEAAAICTAEAOw%3D%3D>

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] <http://tools.ietf.org/html/rfc2397>
[2] <http://software.hixie.ch/utilities/cgi/data/data>

Oh.. As <http://bitworking.org/news/Sparklines_in_data_URIs_in_Python>
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
application).

Ciao, Michael.

Jun 27 '08 #5
On Jun 20, 1:52 am, Michael Ströder <mich...@stroeder.comwrote:
Matt Nordhoff wrote:
Matt Nordhoff wrote:
You could use data: URIs [1].
For example, a 43-byte single pixel GIF becomes this URI:
<data:image/gif;base64,R0lGODlhAQABAIAAAP%2F%2F%2F%2F%2F%2F%2F yH5BAEAAAEALAAAAAABAAEAAAICTAEAOw%3D%3D>
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] <http://tools.ietf.org/html/rfc2397>
[2] <http://software.hixie.ch/utilities/cgi/data/data>
Oh.. As <http://bitworking.org/news/Sparklines_in_data_URIs_in_Python>
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
application).

Ciao, Michael.
This sounds like the way I want to go, it's just a matter of figuring
it out. Is it just a matter of putting a function call in an img tag?

I'll give the URI thing a try, too,
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Wayne | last post by:
I have a script that uses filesystemobject that reads files from a given path, in my case images. It is running on a server that is 2000 adv svr w/ all current patches. The script prior to some...
3
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1, VS.NET (c#) .Net framework 1.1, IIS 5.1. In a...
10
by: Neo Geshel | last post by:
I am seeking to hand-roll my own blog in ASP.NET 2.0 and SQLExpress 2005. Why? Because I can. Because I will gain experience. The one thing that has me stumped at square one is inline images....
6
by: wattanabi | last post by:
Greetings, I'm attempting to layout a bunch of images in a grid using DIV's instead of a table. I currently have a 3x6 table that I need to convert to css. I've seen various example of a 3 to 4...
2
by: mouseit101 | last post by:
Hi, I'm writing a script that would (hopefully) search google images for whatever, and then return a list of URLs for the image. Right now I have: $dom = new DomDocument(); $url =...
0
by: Frenchie | last post by:
Hi, I have created a very neet menu from an example found on the MSDN library at: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.menuitembinding.imageurlfield.aspx My...
1
by: Cerebral Believer | last post by:
Hi folks, I am using the following code for mouse over (roll-overs) in my XHTML code. <a onmouseover="document.getElementById('sitemap').src = '../images/buttons/sitemap_mo.jpg';"...
4
toxicpaint
by: toxicpaint | last post by:
Hi, can anyone give me a hand. I'm currently displaying 4 random images at the top of a page. I did this using an array of 35 pictures and then writing them to page. The problem I have is that in...
5
by: remon87 | last post by:
I need some help. I have javasript that creates the submenu but it works if I have a text with css. I need it to do the same with a roll over images. so when I click on the image the submenu...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.