We have an (asp.net core 2.2) app (public portal) with Bootstrap 4.x, whereby the customer can upload his own images and use the img-fluid on various views (with different sizes) in flex.
The images are scaled (resized) automatically by the upload to the size how the images are showed to the end users ("query view").
On the editing view, we have to show the images with correct aspect ratio but smaller.
The end user view is optimized to show the images in landscape ( 1 ) format, but the customer also is able to upload images in portrait ( 2 ) format (the images then have to be scaled to a given height) what is not a problem on the end user view, as the images are scaled automatically correctly by the upload, but in the (smaller) editing view, it definitely is a problem...

Per default, the .img-fluid class applies max-width: 100%; and height: auto; to the image:
In my case (I set the width), this leads to a scale of a portrait image to the full width ( 2 ) , what shows the image
way to high ( 3 ).
I want to scale the height to to a given height ( 4 ) (in the example it is 185 Pixel).
Principally, I would be able to overwrite the max-height to the img-fluid to have the needed hight:
img-fluid {
max-height: 185px;
}
But this would be a really bad idea, as it would affect all images on all views.
The only solution, that works for my case is:
to overwrite the max-height to 100%:
.img-fluid {
max-height: 100%;
}
and set the height to the container control explicitly to the needed height:
<div id="WirUeberUnsFotoUpload" style="height:185px">
<div> --- Noch kein Foto hochgeladen --- </div>
</div>
Note: The Text to the div „ --- Noch kein Foto hochgeladen --- „ is replaced by the uploaded image via JQuery at runtime.
This leads to the wanted result ( 5 ) :

This way, the image ( 5 ) is scaled correct to the needed height ( 4 ) and don’t affect the other views.
Note: Both, to set the height to the container and to set max-height: 100% is needed.