我试图找到图像aspectratio,所以 width/height 给出任何图像的纵横比 . 但是当我将 max-widthmax-height 设置为 somevalue 时,我想设置图像宽度和高度,就像设置图像的宽度和高度一样 .

如何进行此计算以查找具有正确宽高比的图像的宽度和高度?

new_width = width/height*user_definedwidth;

像这样,但我想计算任何图像的宽度和高度?

How mozilla sets both width and height with aspect ratio when max-width or max-height have set.

我需要显示任何用户上传的图像具有正确的宽高比,但需要调整大尺寸图像的大小 .

<img src="http://hdcomputerwallpaper.com/wp-content/uploads/2013/12/Puppy-images.jpg" style='max-width:200px;'/>