I had the same question as I could not find an answer, invent and resolved as follows:
<?php
$svgfile = simplexml_load_file("svgimage.svg");
$width = substr($svgfile["width"],0,-2);
$height = substr($svgfile["height"],0,-2);
?>
Note that the SVG file I used was created in Adobe Illustrator. So, the SVG code of the image starts as follows:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="400px" height="738px" viewBox="0 0 400 738" enable-background="new 0 0 400 738" xml:space="preserve">
...
Thanks to this, I could get width and height values.
And I use substr
because $svgfile[width]
returns the value with "px" suffix. I could also use viewBox value and split it to get the values.
Greetings from Santiago, Chile
viewbox
, but it seemsviewbox
should also set theDimensions
manually, not automatic. how to transfer aSVG
toviewbox
xml file
? it should maintain the image aspect ratio. Thanks. – Acrimony