# How do I load images?

**URL:** <https://discourse.processing.org/t/how-do-i-load-images/34965>\
**Category:** Beginners\
**Created:** [February 3, 2022, 8:59pm UTC](https://discourse.processing.org/t/how-do-i-load-images/34965 "2022-02-03T20:59:06Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 3, 2022, 9:30pm UTC](https://discourse.processing.org/t/how-do-i-load-images/34965/21 "2022-02-03T21:30:16Z")

</div>

can you send the link to your sketch?

here [p5.js Web Editor](https://editor.p5js.org/Chrisir10/sketches/h2ifzLMNf)

---

<div class="post-metadata">

**Author:** ![tazrXxx](https://avatars.discourse-cdn.com/v4/letter/t/90ced4/32.png) [@tazrXxx](https://discourse.processing.org/u/tazrXxx)\
**Post date:** [February 3, 2022, 9:30pm UTC](https://discourse.processing.org/t/how-do-i-load-images/34965/22 "2022-02-03T21:30:32Z")

</div>

I’m using Chrome and my OS is Chrome OS because I have a Chromebook 🙂

---

<div class="post-metadata">

**Author:** ![tazrXxx](https://avatars.discourse-cdn.com/v4/letter/t/90ced4/32.png) [@tazrXxx](https://discourse.processing.org/u/tazrXxx)\
**Post date:** [February 3, 2022, 9:32pm UTC](https://discourse.processing.org/t/how-do-i-load-images/34965/23 "2022-02-03T21:32:06Z")

</div>

Well, I didn’t use the web editor, I used a Text editor. Do you want me to copy and paste all my code into the web editor?

Or do you want me to send my code as a file?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 3, 2022, 9:35pm UTC](https://discourse.processing.org/t/how-do-i-load-images/34965/24 "2022-02-03T21:35:17Z")

</div>

> [@tazrXxx](#):
>
> I used a Text editor.

I am not sure I understand. Can the Text Editor run your code? You mean an IDE? Which one?

Did you try [https://editor.p5js.org/](https://editor.p5js.org/) ?

---

<div class="post-metadata">

**Author:** ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)\
**Post date:** [February 3, 2022, 9:35pm UTC](https://discourse.processing.org/t/how-do-i-load-images/34965/25 "2022-02-03T21:35:50Z")

</div>

Make sure the image is there in the correct place among the files in the Web Editor.

_EDIT (February 3, 2022)_:

… that is if you use the code in the original post. Alternatively, you can adapt the code to access an image from a remote location via a web address, as @Chrisir did in a Web Editor example above.

---

<div class="post-metadata">

**Author:** ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)\
**Post date:** [February 3, 2022, 11:10pm UTC](https://discourse.processing.org/t/how-do-i-load-images/34965/26 "2022-02-03T23:10:02Z")

</div>

Here it is, as a screen capture, with the original code and image in the Web Editor, executing as intended:

 ![loading an image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/760b0a247ff4ee991af76fd114d021757e902229.jpeg)

Note the folder and files listed in the upper left.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [February 4, 2022, 2:07am UTC](https://discourse.processing.org/t/how-do-i-load-images/34965/27 "2022-02-04T02:07:48Z")

</div>

> [@tazrXxx](#):
>
> It just shows nothing.

[p5js.org/reference/#/p5/preload](https://p5js.org/reference/#/p5/preload)  
[Glitch.com/~preload-image-masks](https://Glitch.com/~preload-image-masks)

> [@Pls critique my code!](https://discourse.processing.org/t/pls-critique-my-code/12855/2):
>
> Not at all! Callback preload() is the single best place to load assets. star_struck BtW, you’ve got some missing indentation on your posted code. woozy_face We can use [Beautifier.io](http://Beautifier.io) in order to clean up our JS code. wink Here’s my own take on your sketch (Warning: Not fully tested!): sunglassesindex.html: \<!DOCTYPE html\> \<meta charset=utf-8\> \<meta name=viewport content=width=device-width,initial-scale=1\> \<script defer src=https://cdn.JsDelivr.net/npm/p5\>\</script\> \<script defer s…

---

<div class="post-metadata">

**Author:** ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)\
**Post date:** [February 4, 2022, 6:13am UTC](https://discourse.processing.org/t/how-do-i-load-images/34965/28 "2022-02-04T06:13:08Z")

</div>

> [@GoToLoop](#):
>
> Callback preload() is the single best place to load assets.

By all means, @tazrXxx, try @GoToLoop’s suggestions.

What happens if, on the Chromebook, you start with the code from your original post, and simply move the statement that loads the image into a `preload()` function? With that change having been made, the `preload()` function would be as follows:

```auto
function preload() {
  playerImg = loadImage(playerData.img);
}

```

This would be your `setup()` function:

```auto
function setup(){
  createCanvas(720, 400);
}

```

> [@Chrisir](#):
>
> Can the Text Editor run your code?

@tazrXxx, when the code is open in the text editor, how are you actually running it? You need to activate your HTML file, so that it opens in the browser, but we don’t know how you are doing that.

[Previous page](https://discourse.processing.org/t/how-do-i-load-images/34965.md?page=1)
