1

I'm creating a webpage that takes an image from another website, one that I do not own, and removes a solid colour background. To achieve this, I'm using MarvinJ's image.setColorToAlpha(0,0);. This is working well enough with a local copy of the image but when I try to use the image url it gives me a CORS error

Reason: CORS header ‘Access-Control-Allow-Origin’ missing

The image allows me to place it on the webpage but not access it with MarvinJ.

I have tried following this to store it locally but it gives me the same error and I don't really know doing with it anyway.

Is there a way that I can somehow store the image locally and then use that copy? I am looking to this through the browser if possible.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tom Gionfriddo
  • 410
  • 2
  • 8

1 Answers1

2

You need a server-side script on your own website which takes the URL of the image, retrieves the image and returns it to the caller.

Then from JavaScript access the image via your server-side script.

NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • I have the page hosted from Github atm so that would be a last ditch attempt. But ill definitly try it if i have to, thanks – Tom Gionfriddo May 01 '19 at 13:19
  • @TomGionfriddo if this is just for testing, you can use a service like crossorigin.me – NineBerry May 01 '19 at 13:29
  • That's what I would do as well, if I were in a situation where the service I am designing would absolutely need to make use of assets on Internet -- the restrictions in user agents, like CORS, unfortunately make it impossible to just fetch resources across website domain bounary, unless the object of access explicitly allows it through one of CORS-enabled headers. But you can use a HTTP client that does not have such restrictions, as a proxy. – Armen Michaeli May 01 '19 at 13:42
  • @NineBerry im looking at crossorigin.me, It doesn't seem to be working for me. It gives a Cloudflare "Error 522 Connection timed out" error when I try to use it. – Tom Gionfriddo May 02 '19 at 07:51
  • @TomGionfriddo i haven't used it for some time. It's not very stable – NineBerry May 02 '19 at 11:28