# “loadImage() inside settings()” rule is unclear

**URL:** https://discourse.processing.org/t/loadimage-inside-settings-rule-is-unclear/198
**Category:** Processing
**Created:** [May 21, 2018, 12:21pm UTC](https://discourse.processing.org/t/loadimage-inside-settings-rule-is-unclear/198 "2018-05-21T12:21:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![HGDoSNmPmz6fyxC](https://avatars.discourse-cdn.com/v4/letter/h/b5a626/32.png) [@HGDoSNmPmz6fyxC](https://discourse.processing.org/u/HGDoSNmPmz6fyxC)
#### Post date: [May 21, 2018, 12:21pm UTC](https://discourse.processing.org/t/loadimage-inside-settings-rule-is-unclear/198/1 "2018-05-21T12:21:10Z")

</div>

The [documentation on `settings()`](https://processing.org/reference/settings_.html) says (emphasis added):

> The settings() method runs before the sketch has been set up, so other Processing functions cannot be used at that point. For instance, **do not use loadImage() inside settings()**. The settings() method runs “passively” to set a few variables, compared to the setup() command that call commands in the Processing API.

Why? I have a sketch whose dimensions should be the dimensions of the image it interacts with. Instead of changing the hardcoded `size()` values in `setup()` every time I test a new image, I instead:

```auto
void settings() {
  my_image = loadImage("image.png");
  size(my_image.width, my_image.height);
}

```

This works well, as I expected, and seems to be the only to accomplish the task. So why does the documentation tells us not to do it?

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [May 21, 2018, 2:44pm UTC](https://discourse.processing.org/t/loadimage-inside-settings-rule-is-unclear/198/2 "2018-05-21T14:44:56Z")

</div>

Interesting that [the right way](https://github.com/processing/processing/wiki/Window-Size-and-Full-Screen) of doing it…

```auto
PImage my_image;
void settings() {
  size(100, 100, P2D);
}
void setup() {
  surface.setResizable(true);
  my_image = loadImage("image.png");
  surface.setSize(my_image.width, my_image.height);
}
void draw() {
  image(my_image, 0, 0);
}

```

crashes for me when using P2D:

![2018-05-21-164031_492x23_scrot](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/4274372b32828e1b04a3b5dce4a81289f21d5c75.png)

Using your approach @HGDoSNmPmz6fyxC works both for default and P2D modes (I’m on Linux)

If I delay resizing the sketch then it works fine:

```auto
PImage my_image;
void settings() {
  size(100, 100, P2D);
}
void setup() {
  surface.setResizable(true);
}
void keyPressed() {
  my_image = loadImage("image.png");
  surface.setSize(my_image.width, my_image.height);
}
void draw() {
  if (my_image != null) {
    image(my_image, 0, 0);
  }
}

```

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [May 21, 2018, 6:21pm UTC](https://discourse.processing.org/t/loadimage-inside-settings-rule-is-unclear/198/3 "2018-05-21T18:21:43Z")

</div>

> [@hamoid](#):
>
> Interesting that the right way of doing it… […] crashes for me when using P2D

Have you checked if there is already an [open issue](https://github.com/processing/processing/issues)? This sounds like perhaps it should be reported. The code may have evolved out from under the docs, for example.

---

<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: [May 21, 2018, 7:22pm UTC](https://discourse.processing.org/t/loadimage-inside-settings-rule-is-unclear/198/4 "2018-05-21T19:22:16Z")

</div>

1. [https://Forum.Processing.org/two/discussion/18033/how-to-set-processing-to-automatically-detect-an-image-size-and-set-it-as-a-background#Item\_1](https://Forum.Processing.org/two/discussion/18033/how-to-set-processing-to-automatically-detect-an-image-size-and-set-it-as-a-background#Item_1)

2. [https://Forum.Processing.org/two/discussion/16705/null-pointer-exception-when-loading-image-in-settings-p3-1-1#Item\_1](https://Forum.Processing.org/two/discussion/16705/null-pointer-exception-when-loading-image-in-settings-p3-1-1#Item_1)
