From f0424ee65afcec52bf6cd924c92e2415451fa0a6 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 12 Sep 2023 12:43:47 +0200 Subject: [PATCH] wait #6270 @0:20 --- src/Graphics/Image.php | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Graphics/Image.php b/src/Graphics/Image.php index 7a2c578..1529c67 100644 --- a/src/Graphics/Image.php +++ b/src/Graphics/Image.php @@ -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) { -- 2.39.5