474,045 Members | 20,547 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?MyParam eter"
---Parse Image content ...

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

Any Idea ?

Thierry

Mar 2 '07 #1
5 28676
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.g if"
</script>
<button onClick="if(IM. fileSize) alert(IM.fileSi ze);">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?MyParam eter"
---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.c ontentDocument. 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
10668
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 = ImageOrig.Width; The problem is this operation takes quite a bit of time to complete (100+ ms).
1
5194
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 *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
3
4133
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 the file at a time and after displaying the file we have to lseek 500 bytes back in the file And read file from 500 to 1000. we have to read this type upto end of
2
1419
by: joe | last post by:
how to read image from sql server to show in a image
3
1573
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 the port will block until a time out, since there
6
15765
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
1059
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
3254
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
4177
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 in /home/oneowner/public_html/admincp/system_cls.php on line 0" Here is the URL of the website. http://www.oneownercar.com.au/index_20081120.php
5
12178
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, then upon receiving the bytes comprising the image, it should write these bytes into a newly created file such that an image file is created. The image is of .jpg format. I really don't know how to create a program that receives and stores bytes...
0
10546
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10337
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
12140
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11602
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12023
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8698
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6652
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.