Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Getting at the binary data in an Image object

Reply
Thread Tools

Getting at the binary data in an Image object

 
 
dirtside
Guest
Posts: n/a
 
      12-08-2005
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.

 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      12-08-2005
"dirtside" <> wrote in message
news: 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");


 
Reply With Quote
 
 
 
 
Jeff North
Guest
Posts: n/a
 
      12-08-2005
On 7 Dec 2005 17:10:37 -0800, in comp.lang.javascript "dirtside"
<> 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
---------------------------------------------------------------
: Remove your pants to reply
---------------------------------------------------------------
 
Reply With Quote
 
dirtside
Guest
Posts: n/a
 
      12-08-2005
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 ).

 
Reply With Quote
 
McKirahan
Guest
Posts: n/a
 
      12-08-2005
"dirtside" <> wrote in message
news: 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);


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
best way to store binary image data in a variable using image magick Jack Perl Misc 2 01-25-2008 10:59 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
image object, onload, onerror, recursive binary search bjarthur Javascript 1 02-23-2005 04:10 AM
Getting binary image data from SQL Server =?Utf-8?B?TmF0aGFuVg==?= ASP .Net 1 02-02-2005 01:17 PM
Advice needed: reading image (binary) data from a db, to be placed in an Image control ?? Denise Smith ASP .Net 2 11-22-2003 02:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57