Here is what I was after... and I think what the OP wanted:
- If image is tall fit height (potentially letterboxing on left/right)
- If image is wide fit width (potentially letterboxing on top/bottom)

Here is the CSS...
.Image_Container {
position: absolute;
top: 0;
width: 100vw;
height: 100vh;
}
.Image {
width: 100%;
height: 100%;
object-fit: contain;
}
body {
background: orange;
margin:0;
}
Here is the HTML...
<div class="Image_Container">
<img class="Image" src="https://picsum.photos/400/800" />
</div>
<div class="Image_Container">
<img class="Image" src="https://picsum.photos/800/301" />
</div>
Here is the Code...
https://stackblitz.com/edit/web-platform-9s6clh?file=styles.css
Disclaimer:
I am sure this can be simplified, hopefully not with some weird specs like -moz-moz, -webkit POLUTION, forget those none sense units like px,em,... viewport units all the way :)
I am no CSS guru, just hacking myself away into all this garbage languages/frameworks that fail to provide the obvious for the average human.