1

Possible Duplicate:
Get image data in Javascript?
Convert an image into binary data in javascript

I have:

A string containing a link to an image on a remote server.

I want:

To 'get' this image, purely through client-side Javascript, and convert it to a base64 dataURL representation.

Is this possible? How?

Community
  • 1
  • 1
Bee San
  • 2,605
  • 2
  • 20
  • 19
  • This is not the same as the other questions because it is requesting from remote server. The linked question does not have that requirement. – 1.21 gigawatts May 14 '17 at 19:59

1 Answers1

3

You can not.

Because the file is on a remote server, you can't use the canvas element's getImageData() method to get the pixel representation of the image.

You'd need to proxy it via a server side script or similar.

alex
  • 479,566
  • 201
  • 878
  • 984
  • 1
    You can set the img element with attribute "crossorigin="anonymous"". This will then allow you to get the image data from the canvas. http://www.w3.org/TR/cors/ – T.Ho Jan 18 '13 at 22:23