From e4a08effd6aa33bda45ea3178142991f7aa97371 Mon Sep 17 00:00:00 2001 From: Anna Dabrowska Date: Thu, 2 Mar 2023 13:31:26 +0100 Subject: [PATCH 1/2] If SVG width and height are not define, set them to 100% --- svg.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/svg.php b/svg.php index abcf427..3fb2655 100644 --- a/svg.php +++ b/svg.php @@ -175,8 +175,8 @@ class SVG { $xml = simplexml_load_file($file, SvgNode::class); $def = hsc((string) $xml->path['d']); - $w = hsc($xml['width']); - $h = hsc($xml['height']); + $w = hsc($xml['width'] ?? '100%'); + $h = hsc($xml['height'] ?? '100%'); $v = hsc($xml['viewBox']); return ""; From 32cb5749b36ee85781ebbad564879cd97b5ed3a1 Mon Sep 17 00:00:00 2001 From: Anna Dabrowska Date: Thu, 2 Mar 2023 16:14:23 +0100 Subject: [PATCH 2/2] Do not use SVG width and height directly when embedding images --- svg.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/svg.php b/svg.php index 3fb2655..6688fc8 100644 --- a/svg.php +++ b/svg.php @@ -179,7 +179,12 @@ class SVG { $h = hsc($xml['height'] ?? '100%'); $v = hsc($xml['viewBox']); - return ""; + // if viewbox is not defined, construct it from width and height, if available + if (empty($v) && !empty($w) && !empty($h)) { + $v = hsc("0 0 $w $h"); + } + + return ""; } /**