Get width, height and ratio from SVG images
Closed this issue · 5 comments
I think it would be really neat if we could get the width and height from SVG images from either its width and height or viewbox attributes.
Im using this for example with header logos, to get its ratio to make it responsive in a non painting manor - browser paints are expensive on mobil, especially in the header (critical path) where they're visually present.
$site->image('site-logo.svg')->width();
$site->image('site-logo.svg')->height();
$site->image('site-logo.svg')->ratio();
...
Oh, I never thought about actually parsing the SVG code in order to get the width and height. That's a great idea!!
I just added width and height detection for SVGs to the develop branch :)
That is so cool! I'm excited for this. Thanks 👍
This could maybe be extended a bit further actually.
$site->image('icons.svg#map-marker')->width();
..
Could do its thing, but for an element within the <svg>
with the id of map-marker
🎉
It would also be pretty neat if parts or the entire viewBox="x y width height"
could be grabbed, this is not only scoped at <svg>
elements but also multiple <symbol>
within it.