image handling in js

M

Mike

Hi newsgroup,

I'm just wondering if it is possible to display an image purely from
javascript? For example, it is possible to receive a text string and
document.write() the current document to dynamically recreate the HTML.
Is there a way to create an image by receiving an image binary string
and somehow use js to display it?

This is just out of my curiosity. It might not even be practical.

M
 
J

John Bokma

Mike said:
Hi newsgroup,

I'm just wondering if it is possible to display an image purely from
javascript? For example, it is possible to receive a text string and
document.write() the current document to dynamically recreate the HTML.
Is there a way to create an image by receiving an image binary string
and somehow use js to display it?

This is just out of my curiosity. It might not even be practical.

With Firefox, yes.

<img src="data:xxxxxxxxxxxxxxx......xxxxxxxxxxxxx">

see: http://www.andrewwooldridge.com/blog/2004/10/datafication.html
 
D

Doug Lerner

Hi newsgroup,

I'm just wondering if it is possible to display an image purely from
javascript? For example, it is possible to receive a text string and
document.write() the current document to dynamically recreate the HTML.
Is there a way to create an image by receiving an image binary string
and somehow use js to display it?

This is just out of my curiosity. It might not even be practical.

You can, and it is practical. This snippet is taken from our Web Crossing
server-side JavaScript. It retrieves the user's picture (stored as a
string), prepends a couple of appropriate headers to it and returns the
data, which gets displayed on the response page as the user's thumbnail
image:

function txShowThumbnail() {
wctlEval( 'addResponseHttp( "Content-type: image/jpeg" )' );
wctlEval( 'addResponseHttp( "Expires: Fri, 1 Jan 2010 09:00:27 GMT")' );
var theUser = User.open('.' + form.u);

return theUser.txThumbnail;
}

doug
 
T

Thomas 'PointedEars' Lahn

Doug said:
You can, and it is practical. This snippet is taken from our Web Crossing
server-side JavaScript. It retrieves the user's picture (stored as a
string), prepends a couple of appropriate headers to it and returns the
data, which gets displayed on the response page as the user's thumbnail
image:

function txShowThumbnail() {
wctlEval( 'addResponseHttp( "Content-type: image/jpeg" )' );
wctlEval( 'addResponseHttp( "Expires: Fri, 1 Jan 2010 09:00:27 GMT")'

There is no such built-in method in JS/ECMAScript. Care to elaborate?

I assume this is using XMLHTTP. Whether that is practical or not remains
to be discussed, as there is wide but not yet complete support for that
interface. Furthermore, it does not qualify as being displayed "purely
from JavaScript".
); var theUser = User.open('.' + form.u);

return theUser.txThumbnail;
}

The question was to _display_ an _image_, not to _access_ image _data_. As
John wrote, if you have binary data, there is no reasonable solution but to
use `data:' URIs (misuse of block-level/table elements does not qualify as
being reasonable).


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top