# \[valid reason\] Loading image outside Preload (p5js)

**URL:** <https://discourse.processing.org/t/valid-reason-loading-image-outside-preload-p5js/32234>\
**Category:** Coding Questions\
**Created:** [September 13, 2021, 2:44pm UTC](https://discourse.processing.org/t/valid-reason-loading-image-outside-preload-p5js/32234 "2021-09-13T14:44:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guy\_Yome](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Guy\_Yome](https://discourse.processing.org/u/Guy_Yome)\
**Post date:** [September 13, 2021, 2:44pm UTC](https://discourse.processing.org/t/valid-reason-loading-image-outside-preload-p5js/32234/1 "2021-09-13T14:44:12Z")

</div>

Hello! I want to know if there was a way to make sure an image was loaded when loading it outside Preload. I sometimes get “Uncaught ReferenceError: loadImage is not defined” and sometimes it loads. It doesnt seem to be predictable. **The reason** why I need to load outside preload is because I am creating a “preview art on your wall” module where clients load pictures of their wall at runtime in a product page via a “upload image” button in the page. They can change their wall as they please.

---

<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:** [September 13, 2021, 3:37pm UTC](https://discourse.processing.org/t/valid-reason-loading-image-outside-preload-p5js/32234/2 "2021-09-13T15:37:54Z")

</div>

- Before issuing **loadImage()** assign `null` to the p5.Image global variable.
- Let’s say that variable is named _img_.
- Then inside **draw()** callback have a statement similar to this:
- `img && image(img, width >> 1, height >> 1);`

---

<div class="post-metadata">

**Author:** ![Guy\_Yome](https://avatars.discourse-cdn.com/v4/letter/g/f0a364/32.png) [@Guy\_Yome](https://discourse.processing.org/u/Guy_Yome)\
**Post date:** [September 13, 2021, 3:46pm UTC](https://discourse.processing.org/t/valid-reason-loading-image-outside-preload-p5js/32234/3 "2021-09-13T15:46:34Z")

</div>

It does seem to be working. I’m going to run it about 20 times and if it does not throw the error again I will call this the solution. Thanks.
