]> _ Git - cubist_util.git/commitdiff
wait #6270 @0:20
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Sep 2023 10:43:47 +0000 (12:43 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 12 Sep 2023 10:43:47 +0000 (12:43 +0200)
src/Graphics/Image.php

index 7a2c57836d3575af10345c94732cf2b85ab75aaf..1529c679473b24f5413872d21d54aacda65341b4 100644 (file)
@@ -54,21 +54,30 @@ class Image
                 $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) {