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

Read image as bytes from javascript

Hi.

I am trying to load image from another domain and reading content.
How an I get the Image array of bytes after loading it.

What I want is to call a server (on another domain as the current
page) with parameters
then parse the image content to receive the server response stored in
the image.

With something like that :

Image = new image()
Image.src = "http://myserver2/myQuery?MyParameter"
---Parse Image content ...

The server return the Image stream with the reponse (a string) .

Any Idea ?

Thierry

Mar 2 '07 #1
5 28625
On Mar 2, 11:26 am, thierryParen...@gmail.com wrote:
I am trying to load image from another domain and reading
content. How an I get the Image array of bytes after loading it.
You cannot easily get the contents of loaded resources by any other
means that an XML HTTP request, which will not work across domain,
tends to only provide the contents as a string or an XML DOM and that
string is likely the string of 16 bit code points resulting from
interpreting the input as UTF-8 (which probably will not work well
with image data).

Richard.
Mar 2 '07 #2
thierryParen...@gmail.com wrote:
I am trying to load image from another domain and reading content.
How an I get the Image array of bytes after loading it.

What I want is to call a server (on another domain as the current
page) with parameters then parse the image content to receive the
server response stored in the image.
MSIE knows the 'fileSize' property name:

<script type="text/javascript">
IM = new Image()
IM.src = "http://www.apache.org/images/asf_logo_wide.gif"
</script>
<button onClick="if(IM.fileSize) alert(IM.fileSize);">click</button>

Hope this helps,

--
Bart

Mar 2 '07 #3
I am trying to load image from another domain and reading content.
How an I get the Image array of bytes after loading it.

What I want is to call a server (on another domain as the current
page) with parameters
then parse the image content to receive the server response stored in
the image.

With something like that :

Image = new image()
Image.src = "http://myserver2/myQuery?MyParameter"
---Parse Image content ...

The server return the Image stream with the reponse (a string) .

Any Idea ?

Thierry
I do this all the time-

Your problem is that you don't want your servlet (i'm assuming that's
what the "server on another domain" refers to) returning a string, you
want it to return an image. To do that, you will have to set the
response content type of the servlet to something like image/png, then
just write out the byte array (image) from the servlet. all you have
to do then is set the source of an image to that servlet's url - like
you want.

Mar 2 '07 #4
The server return the Image stream with the reponse (a string) .

If you don't have control over this server, that makes things much
more difficult. In that case, the only thing I can think of is to
write a servlet proxy (that can see that "other domain" that reads in
the image string and somehow (i don't know how or even if it's
possible) converts it to a byte stream and returns an image. Then,
see my previous post.

Mar 2 '07 #5
On Mar 2, 3:26 am, thierryParen...@gmail.com wrote:
I am trying to load image from another domain and reading
content.

How an I get the Image array of bytes after loading it.
You can load it into the page, but AFAIK, it's not possible to get the
img bytes. Let us know if you figure out a way to do this. Once the
onload event fires, you can get the height and width, but that's about
it.

You could perhaps use an iframe or a script tag to get the data,
though. If you set the script's "type" tag to something funky before
setting the src, then the browser won't bother parsing it, and you
could then peek at the properties to see if you can get a glimpse at
the code inside. An iframe would work kind of the same way, but might
be even simpler. Just set the display style to "none", set the src,
and then view the response via contentWindow.contentDocument.innerHTML
once the load event has fired.

Or, you know, you could always just write a proxy that sits on your
server and allows you to pipe through via a curl call to specifically
allowed urls. Then you could use XHR like you oughtta ;)

--
Isaac Z. Schlueter
http://isaacschlueter.com

Mar 3 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Thomas | last post by:
Hi all, Is there a faster way to read image dimensions other than something like: ImageOrig = System.Drawing.Image.FromFile(Filepath); ImageOrigHeight = ImageOrig.Height; ImageOrigWidth =...
1
by: Big Dave | last post by:
Good morning, does anyone know of a good tutorial, or have insight into how to embed an image or javascript file into a custom server control for asp.net? Thanks for your help!!! Big Dave ...
3
by: ramesh | last post by:
can any one help me to solve this one we need to write a c program, Consider a file of size 5000 bytes. Open the file and read to a buffer of size buf; We have to read 1000 bytes only from...
2
by: joe | last post by:
how to read image from sql server to show in a image
3
by: nik | last post by:
Hi, I need to read a 9 byte response from a device on the serial port. read in characters at a time. If I do: serialport.read(4) I would get 8 bytes, and if I did serialport.read(5) I think...
6
by: Francesco Moi | last post by:
Hi. I'd like to flip horizontally an image with JavaScript. Is it possible? Thank you very much.
70
by: quickcur | last post by:
hi can anyone explain me to read image to memory from a url it is very easy in java but it is hard to find an complete solution in c/c++. Thanks,
6
by: swethak | last post by:
Hi, I displayed the image taken from database.How to raotate that image using javascript.plz tell that how to start the logic.plz tell that some reference websites.
3
by: mohsinews | last post by:
Hey, Hope you are all doing good. I am a new bee here. I have recently transfer a website from one hosting server to another and got the error message "Fatal error: Unable to read 4761 bytes...
5
by: shinsengumi | last post by:
Hi, What command/technique is needed in a C program to receive image bytes through socket programming from an HTTP response? I want to develop a program that requests for an image from a server,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.