The code you have mentioned will not work as the text-align property applies to block containers, not inline elements, and img is an inline element.
For more information, you can refer to this document: the W3C spec
You can use the code given below instead of that:
img.center {
display: block;
margin: 0 auto;
}
<div style="border: 1px solid black;">
</div>