Resize multiple images in a uniform size and maintain the ratio


I have multiple images width different sizes, and I want to resize them to fit in a box, and I want to maintain the ratio, and want the images to still look good.

The is 400px by 400px. I have 8 images of different sizes. I want 4 images on the first row and the other four on the last row. So the sizes of each images would be 50px by 50px And I need those images to be in the same ratio as it's original size.

If you want to maintain the ratio, only force one dimension of the image, either the width or the height - not both.