0

I have the same problem with this post context.getImageData() on localhost?, but instead of localhost I am working on a https site so this provokes the problem with the canvas. It there a solution for this case?

Community
  • 1
  • 1
novellino
  • 1,069
  • 4
  • 22
  • 51

1 Answers1

1

These problems arise when you are trying to get data from images loaded across different domains.

One way to solve this (if you are the one in control of serving the images) is by enabling CORS (Cross-Origin Resource Sharing). What this does is basically add an Access-Control-Allow-Origin header to the served image.

You can read all about it in http://www.w3.org/TR/cors/. Your use case is described specifically in http://www.w3.org/TR/cors/#use-cases, section "Not tainting the canvas element".

There is a great resource for understanding how to enable CORS in http://enable-cors.org/. If you're running an apache instance, the easiest way is to use a .htaccess file to enable the headers.

However, if you are not in control of the served images, then you may need to ask permission to use them and probably copy them to your own server.

jbalsas
  • 3,484
  • 22
  • 25