# Image loading from html

**URL:** <https://phaser.discourse.group/t/image-loading-from-html/11633>\
**Category:** Phaser 3\
**Created:** [May 4, 2022, 5:24am UTC](https://phaser.discourse.group/t/image-loading-from-html/11633 "2022-05-04T05:24:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Un\_Gamer](https://avatars.discourse-cdn.com/v4/letter/u/a6a055/32.png) [@Un\_Gamer](https://phaser.discourse.group/u/Un_Gamer)\
**Post date:** [May 4, 2022, 5:24am UTC](https://phaser.discourse.group/t/image-loading-from-html/11633/1 "2022-05-04T05:24:47Z")

</div>

Hello,  
Is it possible to load image directly in html rather than this.load.image().  
I’m trying to load the image using image tag as

```javascript
<img
    src='https://juego-build-server.s3.amazonaws.com/htmlBuilds/441e18079137840864e79a5bb55bab46/e725566d3502bf238694811e613b23a0.png'
    id='frame' style="display: none;">

```

and then try

```javascript
this.load.image('frame', document.getElementById("frame").src);

```

but it loads the image again rather than using the loaded image.

---

<div class="post-metadata">

**Author:** ![jjcapellan](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jjcapellan/32/542_2.png) [@jjcapellan](https://phaser.discourse.group/u/jjcapellan)\
**Post date:** [May 4, 2022, 11:07am UTC](https://phaser.discourse.group/t/image-loading-from-html/11633/2 "2022-05-04T11:07:44Z")

</div>

Hi,  
You can try this:

```javascript
this.textures.addImage('frame', document.getElementById('frame'));

```

Docs: [Phaser 3 API Documentation - Class: TextureManager](https://photonstorm.github.io/phaser3-docs/Phaser.Textures.TextureManager.html#addImage__anchor)

---

<div class="post-metadata">

**Author:** ![Un\_Gamer](https://avatars.discourse-cdn.com/v4/letter/u/a6a055/32.png) [@Un\_Gamer](https://phaser.discourse.group/u/Un_Gamer)\
**Post date:** [May 4, 2022, 12:21pm UTC](https://phaser.discourse.group/t/image-loading-from-html/11633/4 "2022-05-04T12:21:50Z")

</div>

I get this error while playing the game

 ![Screenshot 2022-05-04 175022](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/2/25522d5a1ae21da091d3eaec7c371e364217d450.png)  
Is this due to CORS or problem with code?  
In case if I have a proper link will it work?

---

<div class="post-metadata">

**Author:** ![jjcapellan](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/jjcapellan/32/542_2.png) [@jjcapellan](https://phaser.discourse.group/u/jjcapellan)\
**Post date:** [May 4, 2022, 3:43pm UTC](https://phaser.discourse.group/t/image-loading-from-html/11633/5 "2022-05-04T15:43:49Z")

</div>

Hi,  
I tested the code in one of the phaser examples ([Phaser 3 Examples](http://labs.phaser.io/edit.html?src=src/game%20objects/images/multiple%20image%20rotation.js)) creating an img element with the url of the arrow png file. The code worked correctly.  
In your case, as the image is hosted on an external server, it will have a cross-origin policy that prevents access to images via javascript from outside. My knowledge of CORS is very limited, so I hope another forum member can help you with this.  
Good luck!

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [May 4, 2022, 4:09pm UTC](https://phaser.discourse.group/t/image-loading-from-html/11633/6 "2022-05-04T16:09:52Z")

</div>

You can try

```
<img crossorigin
src='https://juego-build-server.s3.amazonaws.com/htmlBuilds/441e18079137840864e79a5bb55bab46/e725566d3502bf238694811e613b23a0.png'
id='frame' style="display: none;">

```

Beware that if you use `addImage()` there’s no guarantee that the image is complete (downloaded) by then.

---

<div class="post-metadata">

**Author:** ![Un\_Gamer](https://avatars.discourse-cdn.com/v4/letter/u/a6a055/32.png) [@Un\_Gamer](https://phaser.discourse.group/u/Un_Gamer)\
**Post date:** [May 6, 2022, 9:49am UTC](https://phaser.discourse.group/t/image-loading-from-html/11633/7 "2022-05-06T09:49:27Z")

</div>

> [@Un\_Gamer](#):
>
> I get this error while playing the game

I added `img.crossOrigin = 'anonymous';` now it’s working.

> [@samme](#):
>
> Beware that if you use `addImage()` there’s no guarantee that the image is complete (downloaded) by then.

Thanks for the heads-up.
