Image size ratio

Calculate the size ratio of the selected image. The image ratio is the proportion of the width and height.

Examples:

widthheightratio
300px400px3x4
300px300px1x1
101px345px101x345

In the last example, the ratio can't be reduced, and it's the same as the image size.


Requirements:

  • Display an empty ratio by default.
  • Display ratio without spaces around x.
  • Calculate the ratio immediately after selecting the file.
  • The ratio values should be reduced to as smallest values as possible.
  • You can assume the selected file is always a valid image.
  • Width and height are between 1 and 1000.

You are free to add classes, styles, ids, but don't edit or remove data-test attributes.
Create an account to start coding
Create account