By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,828 Members | 2,241 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,828 IT Pros & Developers. It's quick & easy.

image handling in js

P: n/a
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

Jan 19 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Mike" <mi****@gmail.com> wrote:
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...afication.html

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jan 19 '06 #2

P: n/a

On 1/19/06 12:56 PM, in article
11********************@z14g2000cwz.googlegroups.co m, "Mike"
<mi****@gmail.com> wrote:
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

Jan 19 '06 #3

P: n/a
Doug Lerner wrote:
"Mike" <mi****@gmail.com> wrote:
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")'


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
Jan 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.