With the widespread implementation of display: flex vertical centering - even on elements of unknown height is no longer a problem. To center and img (or any other block element) in a containing div (or any other block element) simply apply the following CSS rule to the containing element:
e.g. with this markup:
<div class="container">
<img src="someimage.jpg alt="a useful description">
</div>
use this CSSL
.container {
display: flex;
justify-content: center;
align-items: center;
}
The amazing Rachel Andrews has several great articles at smashingmagazine.com that explain in great detail whats going in with flex alignment. See:
https://www.smashingmagazine.com/2018/08/flexbox-display-flex-container/
https://www.smashingmagazine.com/2018/08/flexbox-alignment/
https://www.smashingmagazine.com/2018/09/flexbox-sizing-flexible-box/
https://www.smashingmagazine.com/2019/04/display-two-value/
and also on alignment in CSS in general:
https://www.smashingmagazine.com/2019/03/css-alignment/
btw you should get in the habit of always providing an alt attribute on your images. See https://support.siteimprove.com/hc/en-gb/articles/115000013031-Accessibility-Image-Alt-text-best-practices