I have a form where users upload an avatar of themselves. Sometimes the file they upload is a perfect square, but often it's not. Here's the HTML I'm using to display the image:
<img src="<?php echo $image; ?>" style="border-radius: 50%; border: 1px #000 solid; height: 70px; width: 70px;"/>
And here's how it turns out depending on the aspect ratio of the image they upload:
enter image description here enter image description here
What I would like to achieve:
- The circle is full, so if the image they upload is the wrong aspect ratio or too small, it zooms to fill the circle.
- The image is centered, so that if they upload a gigantic image, it doesn't just show the top corner where their face is not in the frame.
Is there a good way to do this and account for many different scenarios of image sizes?
I've tried everything!
Use
object-fitandobject-position.