473,386 Members | 1,785 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,386 software developers and data experts.

Getting at the binary data in an Image object

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
4 8284
"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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Blaktyger | last post by:
How can this be done? Images are stored in a LONGBLOB field. When I try to display them, it prints out the binary data as it is... Thank you
4
by: projecktzero | last post by:
Well, I've managed to get an image into a postgre database, but now I'm having trouble getting it out. #! /usr/bin/env python from pyPgSQL import PgSQL def main(): connectdb =...
9
by: Maurizio Penna | last post by:
I, guys. I've embeded an image into a xml file, something like that: <display type="picture" mime="image/png" name = "mosaico6.png"> <!]> </display> Now, I want to display it with a XSL...
8
by: Jerry | last post by:
I have an off-the-shelf app that uses an Access database as its backend. One of the tables contains a field with an "OLE Object" datatype. I'm writing some reports against this database, and I...
3
by: Josema | last post by:
Hi to all, I have stored in a database some binary files (pdfs, and gif images), i would like to know how could i show it, in internet explorer when a person enters for instance in a textbox the...
26
by: Patient Guy | last post by:
Has anyone written code that successfully manipulates binary file data using Javascript? It might---and in the case of doing I/O, will---make use of browser- specific functions (ActiveX/COM with...
6
by: | last post by:
Hi all, is there a better way to stream binary data stored in a table in sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We noticed that in certain heavy load scenarios,...
2
by: Areric | last post by:
Hey all, Another question for you. I have a script that reads in a row from my db into an image object which i defined. It then takes that image and generates a thumbnail by using an output...
6
by: aznimah | last post by:
hi, i'm work on image comparison. i'm using the similarity measurement which i need to: 1) convert the image into the binary form since the algorithm that i've use works with binary data for the...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.