Search code examples
imagehtmlsvgaspect-ratio

Maintain Aspect Ration on SVG Image Calculation Formula


I have an image element of the SVG inb the HTML5,

The image size is: (stretch, preserveAspectRatio is set to "none") width=520px height=240px

then, I modify it to maintain aspect ratio (preserveAspectRatio is set to defer) because width>height, the height still the same = 240px but how can I calculate the new width (it is shrinked because the maintain aspect ratio) is there a formula to this?


Solution

  • viewBox width / viewBox height * 240px I imagine.