# Failed to load image

**URL:** <https://discourse.processing.org/t/failed-to-load-image/43864>\
**Category:** Beginners\
**Created:** [February 9, 2024, 12:37am UTC](https://discourse.processing.org/t/failed-to-load-image/43864 "2024-02-09T00:37:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![the](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@the](https://discourse.processing.org/u/the)\
**Post date:** [February 9, 2024, 12:37am UTC](https://discourse.processing.org/t/failed-to-load-image/43864/1 "2024-02-09T00:37:25Z")

</div>

Hello,

I am teaching a coding class and trying to load and display images on the p5js website as a part of an assignment. I keep running into an error: failed to load error.

```auto
p5.js says: It looks like there was a problem loading your image. Try checking if the file path (https://assets.editor.p5js.org/646bea83ae1b050019dbb6ff/384b84a1-0432-40a0-ad85-de2dd87c6568.png) is correct, hosting the file online, or running a local server.

```

I have the file uploaded into the sketch, and it is showing up in my assets in the account, but the error persists. Am I missing a step here?

my code:

```auto
let img 

function preload(){
  img = loadImage("bart1.png")
}

function setup() {
  createCanvas(400, 400);
  
}

function draw() {
  background(220);
  image(img,0,0)
}

```

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [February 9, 2024, 12:50am UTC](https://discourse.processing.org/t/failed-to-load-image/43864/2 "2024-02-09T00:50:49Z")

</div>

`it is showing up in my assets in the account`

If the image is in a folder called ‘assets’ then you would call it with loadImage(“assets/bart1.png”);

In your code you omitted the semi-colon at the end of loadImage() which could be a typo.

---

<div class="post-metadata">

**Author:** ![the](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@the](https://discourse.processing.org/u/the)\
**Post date:** [February 9, 2024, 12:52am UTC](https://discourse.processing.org/t/failed-to-load-image/43864/3 "2024-02-09T00:52:09Z")

</div>

The file itself is not in a folder currently. I was mainly referring to the “my Sketch \> assets” which it shows all images on the account.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [February 9, 2024, 12:54am UTC](https://discourse.processing.org/t/failed-to-load-image/43864/4 "2024-02-09T00:54:03Z")

</div>

If it’s not in a separate folder then your code should work. Does it help if you add the semi-colon at the end of the line?

---

<div class="post-metadata">

**Author:** ![the](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@the](https://discourse.processing.org/u/the)\
**Post date:** [February 9, 2024, 12:55am UTC](https://discourse.processing.org/t/failed-to-load-image/43864/5 "2024-02-09T00:55:30Z")

</div>

Unfortunately, the semi-colon did not work.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [February 9, 2024, 12:58am UTC](https://discourse.processing.org/t/failed-to-load-image/43864/6 "2024-02-09T00:58:44Z")

</div>

Are you sure that the image is a valid image? Have you previewed it with some other application?

---

<div class="post-metadata">

**Author:** ![the](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@the](https://discourse.processing.org/u/the)\
**Post date:** [February 9, 2024, 1:00am UTC](https://discourse.processing.org/t/failed-to-load-image/43864/7 "2024-02-09T01:00:38Z")

</div>

yes, png file, non corrupt.

I just tried it with `img = createImg("bart1.png") ` and that ended up working on this one, so i might have a workaround. I am curious if there is something with `loadImage()` that I am missing or is a bit askew.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [February 9, 2024, 1:04am UTC](https://discourse.processing.org/t/failed-to-load-image/43864/8 "2024-02-09T01:04:53Z")

</div>

I just tried your code on my system (Mac) with a Chrome browser, using one of my .png images and it ran without error (p5.js WebEditor).

---

<div class="post-metadata">

**Author:** ![the](https://avatars.discourse-cdn.com/v4/letter/t/e36b37/32.png) [@the](https://discourse.processing.org/u/the)\
**Post date:** [February 9, 2024, 1:09am UTC](https://discourse.processing.org/t/failed-to-load-image/43864/9 "2024-02-09T01:09:22Z")

</div>

thanks for testing that, it seems hit or miss. some of the students in my class were able to do it, and some were not. Same basic code, a different outcome.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [February 9, 2024, 1:19am UTC](https://discourse.processing.org/t/failed-to-load-image/43864/10 "2024-02-09T01:19:53Z")

</div>

I ran your code in the Processing IDE with p5.js mode and it also ran without error; image was placed in the sketch folder. I can’t explain why it works sometimes and others not.
