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

Getting at the binary data in an Image object

P: n/a
I've search far and wide for an answer, so forgive me if this is a
stupid question. (Well, it probably is.)

Consider the following javascript:

var foo = new Image();
foo.src = "http://some.server.com/some_filename.gif";

Now, the browser will retrieve 'some_filename.gif' from some.server.com
and put it into the object foo. What I want to do is then subsequently
analyze the actual binary data contained inside some_filename.gif.
(Specifically, I just need to look at the first few bytes.) Is there
any way to do this in just JavaScript?

Thanks in advance for any assistance.

Dec 8 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"dirtside" <ma**@waggoner.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
I've search far and wide for an answer, so forgive me if this is a
stupid question. (Well, it probably is.)

Consider the following javascript:

var foo = new Image();
foo.src = "http://some.server.com/some_filename.gif";

Now, the browser will retrieve 'some_filename.gif' from some.server.com
and put it into the object foo. What I want to do is then subsequently
analyze the actual binary data contained inside some_filename.gif.
(Specifically, I just need to look at the first few bytes.) Is there
any way to do this in just JavaScript?

Thanks in advance for any assistance.


Will this help?

function XML() {
var sURL = "http://some.server.com/some_filename.gif";
var oXML = new ActiveXObject("Msxml2.XMLHTTP.3.0");
oXML.open("GET",sURL,false);
oXML.send();
return oXML.responseBody;
}

alert( XML() );
You'll see a bunch of question marks but that's the binary data.
Substituting .responseText will show you some readable text ...
You can test with:
var sURL = "http://www.google.com/intl/en/images/logo.gif";

You might have to use one of these instead:
var oXML = new ActiveXObject("Msxml2.XMLHTTP");
var oXML = new ActiveXObject("Microsoft.XMLHTTP");
Dec 8 '05 #2

P: n/a
On 7 Dec 2005 17:10:37 -0800, in comp.lang.javascript "dirtside"
<ma**@waggoner.com> wrote:
| I've search far and wide for an answer, so forgive me if this is a
| stupid question. (Well, it probably is.)
|
| Consider the following javascript:
|
| var foo = new Image();
| foo.src = "http://some.server.com/some_filename.gif";
|
| Now, the browser will retrieve 'some_filename.gif' from some.server.com
| and put it into the object foo. What I want to do is then subsequently
| analyze the actual binary data contained inside some_filename.gif.
| (Specifically, I just need to look at the first few bytes.) Is there
| any way to do this in just JavaScript?
|
| Thanks in advance for any assistance.


This is server-side code but you might be able to convert it to
client-side.
http://4guysfromrolla.com/webtech/050300-1.shtml
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Dec 8 '05 #3

P: n/a
That looks like IE-specific code... whatever I do has to be
cross-platform. (I tried the above code in Mozilla, and was unsurprised
when the JavaScript debugger said it didn't know what 'ActiveXObject'
was ;)).

Dec 8 '05 #4

P: n/a
"dirtside" <ma**@waggoner.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
That looks like IE-specific code... whatever I do has to be
cross-platform. (I tried the above code in Mozilla, and was unsurprised
when the JavaScript debugger said it didn't know what 'ActiveXObject'
was ;)).


Try this.
function getRequestObj() {
var ret = null;
var xml = [
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP"];
if (window.ActiveXObject) {
for (var i=0; i<xml.length; i++) {
try {
ret = new ActiveXObject(xml[i]);
break;
} catch(e) {}
}
} else if(window.XMLHttpRequest) {
try {
ret = new XMLHttpRequest();
} catch(e) {}
}
return ret;
}

var sURL = "http://some.server.com/some_filename.gif";
var oXML = getRequestObj();
oXML.open("GET",sURL,false);
oXML.send();

// if you want the "GIF89" content prefix
alert(oXML.responseText);

// if you want the binary data stream
alert(oXML.responseBody);
Dec 8 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.