So how to get the size of an SVG file with javascript when width and height are not set on the svg element? The svg is a string, but could be made a DOM if necessary.
+1
A:
SVGs are scalable vector graphics, and thus can have any arbitrary height and width. Only the ratio is fixed by the format.
jball
2009-12-29 20:59:14
Thanks a lot, i know this, but in the SVG Viever widget i make(http://my.opera.com/SpShut/blog/show.dml/5803641) i need to display thumbnails of SVG files(say 100x100), and if a file has neither width/height nor viewBox attributes, it's displayed at *some size* and only 100x100 portion of it is visible. I want to process the file somehow to get the dimensions and set width/height and viewBox attributes.
Spadar Shut
2009-12-29 21:57:04
You'll have to make an assumption about it then. If your thumbs are 100x100 then why not display the SVG at 100x100?
jball
2009-12-29 22:11:17
Spadar Shut
2009-12-29 22:49:12
With no height and width set in the tag, there is no intrinsic size. You could look through each element in the svg and see what the largest x + width is and largest y + height, and call that the size. I'm not sure that you gain any advantages from that. Conceptually, what are you thinking of as size if not the intrinsic height and width?
jball
2009-12-29 23:28:29
Spadar Shut
2009-12-30 00:19:24
You can also try using an 'img' element instead of 'object', since that will automatically generate a viewBox for you as long as you have 'width' and 'height' set in the svg.
Erik Dahlström
2010-01-02 13:05:21