Javascript 使用aspectratio通过给定的最大宽度和高度查找图像宽度和高度

Javascript 使用aspectratio通过给定的最大宽度和高度查找图像宽度和高度,javascript,css,image,mozilla,aspect-ratio,Javascript,Css,Image,Mozilla,Aspect Ratio,我试图找到图像的纵横比,因此width/height给出了任何图像的纵横比。但是我想设置图像的宽度和高度,就像mozilla在我将max width或max height设置为somevalue时设置图像的宽度和高度一样 如何进行此计算以找到具有正确纵横比的图像的宽度和高度 new_width = width/height*user_definedwidth; 像这样,但我想计算任何图像的宽度和高度 How mozilla sets both width and height with asp

我试图找到图像的纵横比,因此
width/height
给出了任何图像的纵横比。但是我想设置图像的宽度和高度,就像mozilla在我将
max width
max 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.
我需要显示任何用户上传的图像与正确的纵横比,但大尺寸的图像需要调整大小


这个问题可能会对您有所帮助-