I am trying to determine the scale of an image after it has been resized.
By using background-size: cover
on the body background image, I want to ensure that the image maintains its aspect ratio and expands or shrinks to fit both the width and height of the screen.
The image will be centered vertically and horizontally on the screen with any excess cropped out.
If I know:
- The original size of the background image
- The size of the screen/viewport
How can I calculate the actual scaling factor applied to the image?