So after extensive research and tons of jQuery and Javascript solutions I simply could not find a way in which to dynamically scale images to a specified size both horizontally and vertically, I found tons of information on scaling to fit width wise and keep the aspect ratio, or scaling to fit height wise and keep the aspect ratio, but couldn’t figure out whether the image was too tall or too short and adjust accordingly.
So in my example, I had a <div> with a set width of 460px and a set height of 280px, and i need the image to fit, all of itself into that area without stretching (maintaining its aspect ratio)
Now after fiddling around with some width examples my classic algebra skills kicked in.
If I took the width and divided it by the height, so in this case, 460/280 you in return get 1.642… which is the aspect ratio of that area, now if I looked at the aspect ratio of the image, I knew that if it was greater than 1.642… that that meant it was wider than the area, and if the aspect ratio of the image was less than, that it was taller.
So I came up with the following,
And it worked perfectly, so I thought I would share, hopefully this helps some people