# Adapt display window size to image

**URL:** https://discourse.processing.org/t/adapt-display-window-size-to-image/33472
**Category:** Beginners
**Created:** [November 12, 2021, 12:14pm UTC](https://discourse.processing.org/t/adapt-display-window-size-to-image/33472 "2021-11-12T12:14:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![elemau](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@elemau](https://discourse.processing.org/u/elemau)
#### Post date: [November 12, 2021, 12:14pm UTC](https://discourse.processing.org/t/adapt-display-window-size-to-image/33472/1 "2021-11-12T12:14:11Z")

</div>

I want to simply adapt the display window size to the image I load. I read that with processing3 it is not possible anymore to use variables for defining size and that it is necessary to use settings.  
I tried but it does not work.  
This is what I’m doing right now

```auto
PImage img;

void settings() {
  img = loadImage("image.jpg");  
  size( img.width, img.height);
}

void setup() {
image(image, 0, 0);
}

```

---

<div class="post-metadata">

### Author: ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)
#### Post date: [November 12, 2021, 2:06pm UTC](https://discourse.processing.org/t/adapt-display-window-size-to-image/33472/2 "2021-11-12T14:06:48Z")

</div>

this is all a bit of a mess still.

this does work

```auto
PImage img;

void settings() {
  size(0,0, P2D);
}

void setup() {
  img = loadImage("image.jpg");
  surface.setSize(img.width, img.height);
}

void draw() {
  image(img, 0, 0);
}

```

but what’s weird is if you don’t use the draw function and keep your original version with the other adjustments it doesn’t. lol.

```auto
PImage img;

void settings() {
  size(0,0, P2D);
}

void setup() {
  img = loadImage("frodo.jpg");
  surface.setSize(img.width, img.height);
  image(img, 0, 0);
}

```

you basically end up with the correct window size but the image doesn’t display correctly. so yeh use the first version i posted. unless someone else has a way to do this? gotoloop? chrisr?

---

<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: [November 12, 2021, 4:48pm UTC](https://discourse.processing.org/t/adapt-display-window-size-to-image/33472/3 "2021-11-12T16:48:31Z")

</div>

```auto
/**
 * loadImage() + size() in settings() (v1.0.0)
 * GoToLoop (2021/Nov/12)
 * https://Discourse.Processing.org/t/adapt-display-window-size-to-image/33472/3
 */

static final String
  URL = "https://" + "forum.Processing.org/" + "processing-org.jpg", 
  RENDERER = P2D; // JAVA2D, FX2D, P2D, P3D, OPENGL

PImage img;

void settings() {
  img = loadImage(URL);
  size(img.width, img.height, RENDERER);
  noLoop();
}

void draw() {
  background(img);
}

```
