getkirby-v2 / toolkit

This is the deprecated toolkit for Kirby v2.
http://getkirby.com
81 stars 50 forks source link

Get width, height and ratio from SVG images #115

Closed JimmyRittenborg closed 8 years ago

JimmyRittenborg commented 8 years ago

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();
...
bastianallgeier commented 8 years ago

Oh, I never thought about actually parsing the SVG code in order to get the width and height. That's a great idea!!

bastianallgeier commented 8 years ago

I just added width and height detection for SVGs to the develop branch :)

JimmyRittenborg commented 8 years ago

That is so cool! I'm excited for this. Thanks :+1:

JimmyRittenborg commented 8 years ago

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 :tada:

JimmyRittenborg commented 8 years ago

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.