473,406 Members | 2,843 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,406 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 28637
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.