# Pass image path into loadimage

**URL:** <https://discourse.processing.org/t/pass-image-path-into-loadimage/13966>\
**Category:** Coding Questions\
**Created:** [September 13, 2019, 10:45am UTC](https://discourse.processing.org/t/pass-image-path-into-loadimage/13966 "2019-09-13T10:45:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![KicksTV](https://avatars.discourse-cdn.com/v4/letter/k/7bcc69/32.png) [@KicksTV](https://discourse.processing.org/u/KicksTV)\
**Post date:** [September 13, 2019, 10:45am UTC](https://discourse.processing.org/t/pass-image-path-into-loadimage/13966/1 "2019-09-13T10:45:35Z")

</div>

I am having the problem where I want to pass a variable with image path into loadImage(). However, I am getting the error:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/78da05f6d9644d5b2e0d32bf922d6171a6ad8c04.png)

This must be possible but I don’t see anything in docs or online demonstrating this.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [September 13, 2019, 10:53am UTC](https://discourse.processing.org/t/pass-image-path-into-loadimage/13966/2 "2019-09-13T10:53:28Z")

</div>

please link to your project at  
[https://editor.p5js.org](https://editor.p5js.org) so we can see the file, the code,  
( also check the p5.js revision )  
and can play

* * *

example:  
[https://editor.p5js.org/kll/sketches/L4da3ypJO](https://editor.p5js.org/kll/sketches/L4da3ypJO)

---

<div class="post-metadata">

**Author:** ![KicksTV](https://avatars.discourse-cdn.com/v4/letter/k/7bcc69/32.png) [@KicksTV](https://discourse.processing.org/u/KicksTV)\
**Post date:** [September 13, 2019, 11:41am UTC](https://discourse.processing.org/t/pass-image-path-into-loadimage/13966/3 "2019-09-13T11:41:23Z")

</div>

Hey there, here’s the link: [https://editor.p5js.org/kickstv/sketches/IG2wCeLwz](https://editor.p5js.org/kickstv/sketches/IG2wCeLwz)

Im not working in the editor btw. The error I am getting now is different.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [September 13, 2019, 11:47am UTC](https://discourse.processing.org/t/pass-image-path-into-loadimage/13966/4 "2019-09-13T11:47:03Z")

</div>

hm

```auto
display() {
      var loadedImage = loadImage(this.imgPath);  

```

you should not load that image every time draw() // .display() runs

see  
[https://editor.p5js.org/kll/sketches/4JIok7ZaH](https://editor.p5js.org/kll/sketches/4JIok7ZaH)

---

<div class="post-metadata">

**Author:** ![KicksTV](https://avatars.discourse-cdn.com/v4/letter/k/7bcc69/32.png) [@KicksTV](https://discourse.processing.org/u/KicksTV)\
**Post date:** [September 13, 2019, 11:57am UTC](https://discourse.processing.org/t/pass-image-path-into-loadimage/13966/5 "2019-09-13T11:57:21Z")

</div>

Thanks, I didnt want to load the image and save it as an attribute because i wanted to save an instance of a computer as json, but i was getting this error because of loading an image as an attribute. Do you know a work around for this?

[https://editor.p5js.org/kickstv/sketches/EBMBi0o3G](https://editor.p5js.org/kickstv/sketches/EBMBi0o3G)

Thanks for the help

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [September 13, 2019, 12:05pm UTC](https://discourse.processing.org/t/pass-image-path-into-loadimage/13966/6 "2019-09-13T12:05:33Z")

</div>

no idea what you want to save?

```auto

function draw() {
  background(220);
  comp.display();
  comp.move(mouseX, mouseY);

  json = JSON.stringify(comp);

  saveJSON(json, 'comp.json');

}

```

but that would give you about 50 download windows per sec!
