# Variable issue in the setup() block

**URL:** <https://discourse.processing.org/t/variable-issue-in-the-setup-block/21648>\
**Category:** Processing.py\
**Created:** [June 7, 2020, 9:35am UTC](https://discourse.processing.org/t/variable-issue-in-the-setup-block/21648 "2020-06-07T09:35:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![slashwreck](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@slashwreck](https://discourse.processing.org/u/slashwreck)\
**Post date:** [June 7, 2020, 9:35am UTC](https://discourse.processing.org/t/variable-issue-in-the-setup-block/21648/1 "2020-06-07T09:35:02Z")

</div>

I load an `img` in my `setup()`. I can use its attributes like `.width` but when I attempt to use them as parameters to `size()`, I get `NameError: global name ''img'' is not defined`. But before that line, I’m happily referring to them in the `print()` statement.

```auto
def setup():
    global img
    img = loadImage("C:\\Users\foo\\code\\freq_plot\\image_experiment\\bal.jpg")
    
    #all these see the variable "img"
    one_pixel = img.get(40,40)
    print(red(one_pixel), green(one_pixel), blue(one_pixel))
    print(type(img))
    print(img.height, img.width, )
    
    #size(img.height,img.width) #NameError: global name 'img' is not defined'
    size(100,100) # works fine
    
    noLoop()
    
def draw():
    print("done")

```

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [June 7, 2020, 9:58am UTC](https://discourse.processing.org/t/variable-issue-in-the-setup-block/21648/2 "2020-06-07T09:58:47Z")

</div>

Welcome, @slashwreck!

You can use the `settings()` function:

```auto
def settings():
    img = loadImage('bal.jpg')
    size(img.width, img.height)
 
def setup():
    noLoop()
 
def draw():
    print('done')

```

Also, you can use a relative path for your image if you place the image file in the sketch folder (and avoid the whole `"C:\\..."` part).

---

<div class="post-metadata">

**Author:** ![slashwreck](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@slashwreck](https://discourse.processing.org/u/slashwreck)\
**Post date:** [June 7, 2020, 10:12am UTC](https://discourse.processing.org/t/variable-issue-in-the-setup-block/21648/3 "2020-06-07T10:12:08Z")

</div>

Thanks. First I’ve heard of the `settings()` function. Don’t see it referenced in the [reference](https://py.processing.org/reference/). Am guessing it gets called automatically before `setup()`?

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [June 7, 2020, 10:14am UTC](https://discourse.processing.org/t/variable-issue-in-the-setup-block/21648/4 "2020-06-07T10:14:30Z")

</div>

It’s in the Java reference: [https://processing.org/reference/settings\_.html](https://processing.org/reference/settings_.html). I’ll open an issue on GitHub to add it to the Processing.py reference.

Edit: looks like somebody already did.
