$res = $i['infos']['size'];
}
} else if ($ext === 'svg') {
- $svg = simplexml_load_string(file_get_contents($path));
- $attr = $svg->attributes();
- if (!isset($attr['width']) || !isset($attr['height'])) {
- $viewbox = trim($attr['viewBox']);
- $e = explode(' ', $viewbox);
- $width = (float)$e[2];
- $height = (float)$e[3];
- } else {
- $width = (float)$attr['width'];
- $height = (float)$attr['height'];
+ $svgcontent = file_get_contents($path);
+ try {
+ $svg = simplexml_load_string($svgcontent);
+ $attr = $svg->attributes();
+ if (!isset($attr['width']) || !isset($attr['height'])) {
+ $viewbox = trim($attr['viewBox']);
+ $e = explode(' ', $viewbox);
+ $width = (float)$e[2];
+ $height = (float)$e[3];
+ } else {
+ $width = (float)$attr['width'];
+ $height = (float)$attr['height'];
+ }
+ } catch (\Exception $e) {
+ if (preg_match('/viewBox="([^"]*)"/', $svgcontent, $matches)) {
+ $ex = explode(' ', $matches[1]);
+ $width = $ex[2];
+ $height = $ex[3];
+ } else {
+ throw new \Exception('Error while parsing SVG file ' . $path . ' : ' . $e->getMessage());
+ }
}
- $res = array(
- $width,
- $height
- );
+
+ $res = [$width, $height];
} else if ($ext === 'oam') {
$oam = OAMAnimation::getOAMData($path);
if (null !== $oam) {