# Using Images From URLs

**URL:** https://discourse.processing.org/t/using-images-from-urls/39191
**Category:** Beginners
**Created:** [October 10, 2022, 9:52am UTC](https://discourse.processing.org/t/using-images-from-urls/39191 "2022-10-10T09:52:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![s31](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@s31](https://discourse.processing.org/u/s31)
#### Post date: [October 10, 2022, 9:52am UTC](https://discourse.processing.org/t/using-images-from-urls/39191/1 "2022-10-10T09:52:46Z")

</div>

Hi,

if you would ever be so inclined, could someone please show me the correct way to load images using a url as the path. It accepts urls and returns this error so i do not know what i am doing wrong.

TypeError: Failed to execute ‘texImage2D’ on ‘WebGLRenderingContext’: Overload resolution failed.

thankyou!

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [October 10, 2022, 9:55am UTC](https://discourse.processing.org/t/using-images-from-urls/39191/2 "2022-10-10T09:55:30Z")

</div>

Hi @s31,

would you please share your code which producing this error, so we could test and see what is ongoing ?

Cheers  
— mnse

---

<div class="post-metadata">

### Author: ![s31](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@s31](https://discourse.processing.org/u/s31)
#### Post date: [October 10, 2022, 10:13am UTC](https://discourse.processing.org/t/using-images-from-urls/39191/3 "2022-10-10T10:13:57Z")

</div>

```auto
let pic;

function setup() {
  createCanvas(500, 500, WEBGL);
  pic = loadImage('https://imgur.com/gallery/9am48');
}

function draw() {
  background(205, 102, 94);
  texture(pic); 
  sphere(40);
}

```

returns

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/7/0/7057700a32c5a84b3d5c2110f4e3e7281e569a3a.png)

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [October 10, 2022, 10:21am UTC](https://discourse.processing.org/t/using-images-from-urls/39191/4 "2022-10-10T10:21:37Z")

</div>

Hi @s31,

This is an issue with the [CORS policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS).

You can read more about it on those previous threads:

> [@Fetch API cannot load file](https://discourse.processing.org/t/fetch-api-cannot-load-file/3261/7):
>
> Ah, CORS, so we meet again. When trying to access resources (especially in any browser other than Firefox) in a developer-y way, you will often also be doing things that look remarkably like what bad actors do who spoof websites, steal identities, pass viruses, run bot-nets etc – one aspect of which is sometimes called “cross-site scripting,” although suspicious crossings can also be local to a client. CORS (Cross-Origin Resource Sharing) is one of the security measures that prevents you from …

> [@API POST error - not sure what's causing it](https://discourse.processing.org/t/api-post-error-not-sure-whats-causing-it/29311/2):
>
> Hi, If I run the code in the [p5 web editor](https://editor.p5js.org/), I get this error : TypeError {stack: ""} This is somehow cryptic and I don’t really know what is the formatting behind this. However the httpPost function is using the [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) function [behind the scenes](https://github.com/processing/p5.js/blob/0ee26327802f3afc7b0b2591e6c5667c986d8f21/src/io/files.js#L1104) and I tried running that in a new tab (in Firefox): fetch('http://colormind.io/api/', {method: 'POST', body: postData}) .then(data =\> data.json()) .then(json =\> console.log(json)) .catch(err =\> console.log(err)); And effectively there…

EDIT:

as @mnse said, it’s the url that is not the right one, it’s explained in this SO thread how you can get a direct link to an Imgur image:

> <https://webapps.stackexchange.com/questions/95883/how-to-get-direct-link-of-images-on-imgur>

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [October 10, 2022, 10:27am UTC](https://discourse.processing.org/t/using-images-from-urls/39191/5 "2022-10-10T10:27:04Z")

</div>

Hi @s31,

actually you are also not loading an image by that url you are using.

try this…

```auto
let pic;

function setup() {
  createCanvas(500, 500, WEBGL);
  pic = loadImage('https://i.imgur.com/9am48.png'); // real url of the image ...
}

function draw() {
  background(205, 102, 94);
  texture(pic); 
  rect(-width/2,-height/2,width,height);
}

```

Cheers  
— mnse
