Adapt display window size to image

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

PImage img;

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

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

this is all a bit of a mess still.

this does work

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.

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?

/**
 * 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);
}