Is there a way to get a loaded svg's aspect ratio? I want to be able to know the scaling that goes into the preserveAspectRatio property. The documentation states that for meet:
Is there a way to retrieve the aspect ratio that the property somehow knows in JS?
It's fairly easy to get the viewBox's values like described in Phrogz' answer to "Obtaining an original SVG viewBox via javascript":
var svg = document.querySelector('svg');
var box = svg.viewBox.baseVal;
Getting the aspect ratio from that requires just simple math:
var aspectRatio = box.width / box.height;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With