If image is too big, it gets cropped to a square. If image is too small, it gets stretched to fit then cropped to a square.
NOTE: Most browsers these days support object-fit which is a much simpler solution.